w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » SHELL » Page 1
command to delete the oldest .tar file in a directory when a maximum count of .tar files is reached to 10
This is a job for logrotate. logrotate is used the program that manages your log files in /var/log. Example to follow. It can rotate logs based on date or size. Look at /etc/cron.daily/logrotate and /etc/logrotate.conf. You should just be able to put an entry in /etc/logrotate.conf to handle the file your want to rotate. Also see this website: http://www.rackspace.com/knowledge_center/article

Categories : Shell

How do I store the output to a file AFTER cmd execution?
For Shell only: Use tee: tee is a command in command-line interpreters (shells) using standard streams which reads standard input and writes it to both standard output and one or more files, effectively duplicating its input. e.g. robocopy %TOBEZIPPED% %TEMPDIR% *.* /E | tee -a Log.txt If you want to do it in windows you need to use PowerShell http://en.wikipedia.org/wiki/Windows_PowerShel

Categories : Shell

Fast emacs shell-mode?
Set the variables comint-move-point-for-output and comint-scroll-show-maximum-output to nil. This prevents the buffer from continuously scrolling to the end of the output, which requires frequent redisplays.

Categories : Shell

script to convert from ASCII to Unix-style LF
Try this: $ cat ctrl-m.txt -vte ONE ^M$ two ^M$ three$ four$ #!/bin/sh for file in "$@" do if file $file | grep "with CRLF"; then echo "$file has CR/LF. Fixing.." sed -i 's/^M//g' $file fi done After running the script against ctrl-m.txt: $ ./run.sh ctrl-m.txt ctrl-m.txt: ASCII text, with CRLF, LF line terminators ctrl-m.txt has CR/LF. Fi

Categories : Shell

syntax error: unexpected end of file reached
It is likely that your script file has been saved with CRLF line terminators, instead of just LF. The shell does not accept CRLF line endings. Change your editor settings so that the file line endings are LF only.

Categories : Shell

Clojure - Can I assign custom name to a process started using 'lein run'
It's possible though it gets a bit ugly and likely not worth the trouble You would need to make a symlink to java with an alternate name, and modify lein to call that instead of calling java. You could do this by writing a lein plugin for instance. When Linux starts a process the name of the process it uses the name of the file from which the process was run as the name of the process thereafter,

Categories : Shell

Scripting tomcat automatically start missing memory
SOLUTION!!!! Here is the script of which I spoke. This script will automatically restart the Tomcat when it exceeds 95% of physical memory. Enjoy it !! porcentaje=95 usoMemoria=$(ps aux | grep tomcat | grep -v grep | awk '{printf ("%.0f", $4)}') if [ $usoMemoria -ge $porcentaje ]; then echo "Se ha superado el tope (95%) de memoria que se ha establecido para el Tomcat. Se procede a su rein

Categories : Shell

Sum of columns based on Minute
This problem could be solved a million different ways: sed, awk, python, etc. Here is how you can do it with common bash commands. #!/bin/bash # extract the unique set of hours from the input (i.e. 11, 12, 13, 22, 23) # hours=$(cut -f 1 -d . test.txt | sort -u) for hour in $hours; do # initialize sum for this hour # count=0 # extract the number following the ':' # for

Categories : Shell

Bash pipeline output is diff between in groovy and in terminal
you can not use | here as it is handled by the shell. either use sh -c to execute or pipe yourself. See http://groovy.codehaus.org/Process+Management def p = ['sh', '-c', 'ls /tmp | grep groovy'].execute() p.waitFor() println p.text or def p1 = 'ls /tmp'.execute() def p2 = 'grep groovy'.execute() p1 | p2 p2.waitFor() println p2.text

Categories : Shell

Using a variable in an awk Bourne shell script
Change: /theCountry/{ to: $0 ~ theCountry { and read http://www.gnu.org/software/gawk/manual/gawk.html#Computed-Regexps

Categories : Shell

Unix Script Search pattern and append next line to that appropraite
Here is one solution: $ awk 'NR==1{printf "%s",$0;next;} /^:/{printf " %s",$0;next} {printf " %s",$0;} END{print""}' file :20:abcd :28D:a :50H:/1 2 3 4 5 :30:020108 Here is another that uses fewer commands but has slightly more subtle logic: $ awk '{printf "%s%s",(/^:/ && NR>1)?" ":sp,$0;sp=" "} END{print""}' file :20:abcd :28D:a :50H:/1 2 3 4 5 :30:020108 Explanation Both solu

Categories : Shell

Need to pass the user input (date) into DB2 query in Unix shell script
Assuming that the second invocation of db2 was surrounded by back quotes (as now shown in the reformatted question), then the problem is in the read line. It should be: read DATE You don't prefix the name with $ in a read statement. That was taking the value assigned to $DATE and trying to use that as the variable name, which doesn't work. You should probably use $(db2 "SELECT …") notation

Categories : Shell

How to keep process backgrounded after script is done?
After researching, I learned that (tty input) means the process is waiting for terminal input, but it doesn't actually take input from me (someone must've wrote something hacky). To solve the problem, I gave it fake input: lein servlet run </dev/zero & Now it works. :D

Categories : Shell

Running Drupal 6 cron from shell won't work
Solved. Instead of setting $_SERVER variables as described in that example I used part from /scripts/drupal.sh $_SERVER['HTTP_HOST'] = 'default'; $_SERVER['PHP_SELF'] = '/index.php'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['SERVER_SOFTWARE'] = 'PHP CLI'; $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['QUERY_STRING'] = ''; $_SERVER['PHP_SELF'] = $_SERVER['REQUEST

Categories : Shell

TCSH Makefile - copy file to name and change permissions
A makefile rule should always create a file with the same name as the target. If you want make to be able to tell when it needs to run a rule your rule needs prerequisites. Your rule tells make that it will create the proj3final file but it actually creates the proj3 file. This is going to confuse make. Additionally, your rule gives that target no prerequisites so whenever the proj3final file e

Categories : Shell

Find the sum of length of the selected lines using shell script?
With awk : awk 'NR==2||NR==6||NR==10{sum+=length($0)}END{print sum}' file.txt NR is the current line number || is a OR statement what is preceding {} is the condition what's in {} is the action sum+=length($0) increment the variable sum with the length of the current line the END block is executed @the end when all lines have been read

Categories : Shell

Redirect output of one command to different files in shell script
You can do like this: tab_seperated_string | awk -F" " '{print $2,$3,$4,$5 > "file2"; print $1 > "file1"}' OFS=" " It will then save data to two different files. By setting OFS to , you do not need all the in the print statement. Here is another way if you have many fields that go to one file and first field to another: awk -F" " '{print $1 > "file1"; sub(/[^ ]+ /,""); print $0

Categories : Shell

restrict access based on SSH key
You can try using the command option in the /home/storage/.ssh/authorized_keys file, with a restricted shell, like this: command="cd /home/storage/watson && rbash" ssh-rsa AAAAB3...2Z <- watson's public key command="cd /home/storage/sherlock && rbash" ssh-rsa AAAAB4...R5 <- sherlock's public key Now the user will get a restricted shell in a subdirectory depending on which

Categories : Shell

Combining tail and sed command and redirecting them to new file
sed --unbuffered -e 's/^/192.168.12.1/' /logs/a.log >> b.log tail -f b.log should be enough if you want a file but a simple sed --unbuffered -e 's/^/192.168.12.1/' /logs/a.log will work normaly

Categories : Shell

Shell script to search for a word in a while block of the C program
Some like this? cat file Hi This is a bloc It may have while word Here is Hello too In this block we have while but not the other word awk -v RS="" '/while/ && /Hello/' file This is a bloc It may have while word Here is Hello too Here each block is separated by an empty line. To make awk work in block modus, set RS to nothing. Then search for all line with both while and Hello

Categories : Shell

How to extract fields from 2 different files and store in an output file using shell script?
awk 'NR==FNR{a[NR]=$2; next} {print a[FNR], $2}' file1 file2 As NR stands for Number of Record and FNR for Record Number in the current input File, they are equal when processing the first file. Hence, awk 'NR==FNR { things1; next } { things2 }' file1 file2 means: do things1 when processing the first file. do things2 when processing the second file. a[NR]=$2; next means: store the 2nd fie

Categories : Shell

Build failure while running shell command from Jenkins
Jenkins scripts (and "Execute Shell" build step is a script) are executed with the user that Jenkins runs with. By default, Jenkins runs as jenkins user Your script is executed as "jenkins" user, as is evident from: + whoami jenkins You should be executing your chmod commands for jenkins user, not administrator.

Categories : Shell

What does the following UNIX command mean?
Don't try to make bold code (you can do it, but it is hard: if [ $? -eq 0 ] and indentation does not work properly. Just put a comment after the line if [ $? -eq 0 ] # What does this line mean?. You should add the missing fi for completeness. grep -n "$string" $filename if[$? -eq 0] # What does this command mean? then         echo "string is mat

Categories : Shell

How to create a shell alias with parameters
alias cannot get parameters. Instead, use a function, which in fact is what you are already using. For this, use $1 and not $0 as you are doing ($1 means the first argument you provide). All together, this should work: testfunc () { egrep -v '^[[:blank:]]*#' "$1" | awk 'NF'; } ^^ Note also that this could be handled with a single awk: testfunc () { a

Categories : Shell

Parsing timestamp using sed and embedded command
It's interesting what's happening here. Some pointers: Always single-quote your regex for sed, if possible, when using BASH (etc), especially if using special characters like$. This is why date is being run (with -d @\1) before sed even gets involved. Your "working" echo example isn't, actually (I believe): echo \1 produces 1 (and as above, will do so before sed even gets invoked). This then hap

Categories : Shell

Handle mutiple page templates with durandal (hiding modules for specific views)
//shell.js define(function (require) { var headerVisible = ko.observable(true), pagesWithHeader = [require('page1'), require('page2')], router.on('router:navigation:complete').then(function (page, instruction) { headerVisible(pagesWithHeader.indexOf(page) !== -1); }); return { headerVisible: headerVisible } }); //shell.html <section id="shell">

Categories : Shell

stty in non interactive mode
echo is for whether locally typed characters are displayed on the screen or not (as far as I know). I don't believe that does anything for a script that includes a password in it already. So you can probably just remove those two stty lines entirely as they aren't doing anything useful for you to begin with. Alternatively, if, for some reason, there is (or you believe there is) a reason to keep

Categories : Shell

How can I pipe the hostname into a call to SSH?
Maybe, you want to run: ssh `echo example.com` ssh `your_random_script` When you insert some command into back-quotes, this command is executed, and result stored in unnamed variable. For save/reuse, you can invoke something like: VAR=`your_random_script` ssh $VAR

Categories : Shell

How to store the grep output into a variable inside a loop?
To obtain the number of lines produced by the while loop, the wc word count can be used cd /System/Library/Extensions find *.kext -prune -type d | while read d; do codesign -v "$d" 2>&1 | grep "invalid signature" done | wc -l wc -l the -l option counts the number of lines in the input, which is piped to the output of while Now if you need to count the number of grep outputs in ea

Categories : Shell

Invoke MSYS2 Shell from Command Prompt or PowerShell
We're working hard to fix our messy update procedure, we want it to be trouble-free. You can see some examples of how we invoke MSYS2 from a batch file when we create a new installer in: https://github.com/Alexpux/MSYS2-packages/blob/master/msys2-installer/make-msys2-installer.bat But as @StevenPenny suggests, bash -l -c "pacman ..." is the correct way.

Categories : Shell

How to run regression using makefile
The problem is with export SHELL = /bin/csh -f which I was changing to export SHELL = /bin/bash -f. But finally SHELL := /bin/bash works as answered in How can I use bash syntax in Makefile targets? by @derobert

Categories : Shell

variable assignment in shell script
I think you want this: DIR=${BASH_SOURCE%/*/*} That is, strip the last two path parts from the script's own path, and use that. Run it through realpath or readlink -f if you need to get a canonical path.

Categories : Shell

Round robin algorithm in unix shell script
This will work only on systems that have the stat command. Your question needs lots more information to give you decent answer - UNIX OS for example. This is clumsy for that reason. There better ways to do this. oldestdir=$( stat -c "%n %Y" a1 a2 a3 a4 a5 | sort -k2rn | head -1 | awk '{print $1}') $oldestdir is the name of the LRU directory as @KarolyHorvath pointed out. You cannot "incremen

Categories : Shell

Creation of .ebextensions folder in aws elastic beanstalk
You need to do the following (obviously catering for your requirements): In the root on your packaged software create a folder called .ebextensions drwxr-xr-x 4 root root 4096 Sep 30 13:39 . dr-xr-x--- 7 root root 4096 Nov 4 15:22 .. drwxr-xr-x 2 root root 4096 Nov 4 15:22 .ebextensions In the .ebextensions folder create two files called 02_files.config and 03_container_commands.

Categories : Shell

Environment Variables will not set in shell script
Every program has its own environment. A program can change its environment, and it can cause those changes to be propagated to other programs it launches, but no program can change the environment of another running program. The shell gives special prominence and access to its environment, but it must obey the same rules as any other program. When you run a shell script, that's a new program w

Categories : Shell

shell script for creating multiple image files ascending order
for i in {0..15}; do printf -v name "%02i.jpg" $i; touch "$name" ; done Or, if it is easier to read: for i in {0..15}; do printf -v name "%02i.jpg" $i touch "$name" done When this is done, the following files are created: $ ls 00.jpg 01.jpg 02.jpg 03.jpg 04.jpg 05.jpg 06.jpg 07.jpg 08.jpg 09.jpg 10.jpg 11.jpg 12.jpg 13.jpg 14.jpg 15.jpg Explanation for i in {0..15

Categories : Shell

ksh get exit status in assigment
export VALUE=$(My_Get_Value 10) is not an assignment statement; it is a call to the export command, which takes arguments that look like assignment statements. The easiest fix is to separate the assignment from the call to export. VALUE=$(My_Get_Value 10) mgv_exit=$? export VALUE It doesn't matter if you call export before or after the assignment (as long as you don't call it between the assign

Categories : Shell

shell script to get details about sudo commands executed by any user in a linux machine
You will get some useful info from this link : stackoverflow you can use tail /var/log/auth.log | grep username to get the sudo history !! Hope it helps.

Categories : Shell

Redirecting appcmd output to a variable
If the data must be piped from a process to the other, you need to escape the pipe character. It should be ^| If what you need to do is execute both commands, replace the pipe character with ^&, the command concatenation operator, also escaped

Categories : Shell




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.