Tag Info

New answers tagged

1

In your example apt-get update didn't exit with error, because it considered the problems as warnings, not as fatally bad. If there's a really fatal error, then it would exit with non-zero status. One way to recognize anomalies is by checking for these patterns in stderr: Lines starting with W: are warnings Lines starting with E: are errors You could ...


24

You can simulate a CTRL-Z (which you normally use to temporarily background a process) using the kill command: [tsa20@xxx01:/home/tsa20/software]$ kill -19 $$ [1]+ Stopped sudo -iu tsa20 [root@xxx01 ~]# fg sudo -iu tsa20 [tsa20@xxx01:/home/tsa20/software]$ bash just traps the CTRL-Z key combination. kill -19 sends SIGSTP to the process ...


2

It's nothing to do with SSH. The -x argument to bash is that of bash's set command, which displays the command's arguments in expanded form. This is why the double quoted strings are displayed as single quoted strings. $ cat test.sh echo "here are 'some single quotes' inside double quotes" $ bash -x test.sh + echo 'here are '\''some single quotes'\'' ...


0

Simply give read and execute access to /var/www/ and read write and execute access to ucp cd /var/www/ chmod 777 ucp cd ../../ chmod 555 /var or even complicated by making execute access to /var/www but in this case you have to make sure that user will type a complete path to reach at ucp cd /var/www chmod 777 ucp cd ../../ chmod 111 /var Note:- ...


1

I do not think it would make much sense to implement such functionality in 'cd'.. It would work if every subdir had only one sub-subdir, but what if there's a tree [i.e. several subdirs in a dir]? Which path should it take? 'cd' is not a mind reader. Consider the following two direcroty trees: <some_parent_dir> | |-<subdir> | | | ...


2

if lastdir is the only directory of that name in your directory hierarchy, you might get away with this in bash (although it may take a while to run) shopt -s globstar cd **/lastdir


2

$1 is the first argument to the script, i.e. list.txt LIST=$1 simply copies that filename to the LIST variable, so $LIST now contains lists.txt as well -- it doesn't contain 12345. while read PDF do ... done < ${LIST} starts a loop whose standard input is redirected to the file list.txt, and each time through the loop it reads a line from the ...


0

This command works for Debian based and Redhat based distributions: Using tr filter, you convert the document to one-word-per-line format and then count the first line which contains the distribution name. tr -s ' \011' '\012' < /etc/issue | head -n 1


1

Changing the login shell does not necessarily prevent users from authenticating (except in some services that check if the user's shell is mentioned in /etc/shells). People may still be able to authenticate to the various services that your system provides to unix users, and may still be authorized to perform some actions albeit probably not run arbitrary ...


-2

sed \$r01.txt new.txt sed \$r02.txt new.txt


1

You can use chsh command: ~# chsh myuser Enter new shell details when requested: Login Shell [/bin/sh]: /bin/nologin Or shorter version: ~# chsh myuser -s /bin/nologin


3

While an alias is one way to do it, this can be done with eval as well - it's just that you don't so much want to eval the command execution as you want to eval the command declaration. I like aliases - I use 'em all the time, but I like functions better - especially their ability to handle parameters and that they needn't necessarily be expanded in command ...


0

Your line confused me a bit as it was not clear what both occurrences of "test" are supposed to be. - Therefore I really understand that your shell is confused, too. ;) If I understand correctly the first "/tmp/test" should correspond with the old output of the command and the second one corresponds with the new output. You can be sure that stdin will ...


5

Yes, that's a race condition. The problem is that the shell starts all processes in the pipeline at the same time and tee truncates the output file on startup. If tee is faster then comm the file is empty for comm otherwise it is not. The pipeline behaviour can be seen if you run this several times (mabe in a loop): date '+first: ...


0

I would throw sed in directly after sort and have it write out the files as you want them all in one go: wc -l /group/book/four/word/*|sort -n | sed 'w ./not_as_yet_touched.txt 1,2s/^[0-9 ]*//w ./first_two_lines_without_line_numbers_or_leading_spaces.txt s|.*/||w ./everything_up_to_first_slash_trimmed.txt' As written, sed will still autoprint the ...


4

Since date treats non-specifiers as literals you could use the format string to construct a simple arithmetic expression for the current number of minutes, and then evaluate the result using the shell's built-in arithmetic. For example, in bash printf "$(( $(date '+%H * 60 + %M') ))\n" If your shell does not support arithmetic, you could use an external ...


1

GNU date and bash: daystart_sec="$(date --date="today 00:00:00" +%s)" now_sec="$(date +%s)" echo $(((now_sec-daystart_sec)/60))


0

You get the list of files with pathname expansion: cd /group/book/four/word echo * # or into a file echo * >/path/to/filelist.txt You can delete everything in a line from the start up to (including) the first space (or group of spaces) with this sed command: sed 's/^[^ ] *//g' I don't see what od has to do with that. sed can be limited to the ...


2

Common mistake, wrong order of redirection, try this: … sendmail_alive.sh >/tmp/sendmail_alive.log 2>&1 It works like this: file descriptor stdout to /tmp/sendmail_alive.log file descriptor stderr to the value of stdout (/tmp/sendmail_alive.log) With your order, you first point the stderr where originally was stdout and you get the stderr ...


0

The next awk statement will skip the current line, that is useful if you have to match multiple blocks in your script. awk ' /^#/ {next} / pattern 1 / { } / pattern 2 / { } ' filename


1

Using grep: grep -vE "^#" or grep -E "^[^#]"


-1

sed 's/#.*//' This gets rid of comments, even if they don't start at the first column.


1

awk -F: '/^[^#]/ { print $2 }' /etc/oratab | uniq


11

To be able to time a subshell, you need the time keyword, not command. The time keyword, part of the language, is only recognised as such when entered literally. Even entering "time" won't work let alone $TIME (and would be taken as a call to the time command instead). You could use aliases here which are expanded before another round of parsing is ...


1

You don't need to install Expect on the server. Write an Expect script instead of running expect from a shell script. Have the Expect script itself spawn the SSH client, connect to the server and then loop through the numbers. To save yourself some effort you can record a session where you log in to the server and try some number with autoexpect. Save the ...


5

Depending on the version of sed on your system you may be able to do sed -i 's/Some/any/; s/item/stuff/' file You don't need the g after the final slash in the s command here, since you're only doing one replacement per line. Alternatively: sed -i -e 's/Some/any/' -e 's/item/stuff/' file The -i option tells sed to edit files in place; if there are ...


6

You can chain sed expressions together with ";" %sed -i 's/Some/any/g;s/item/stuff/g' file1 %cat file1 anything 123 stuff1 anything 456 stuff2 anything 768 stuff3 anything 353 stuff4


5

Multiple expression using multiple -e options: sed -i.bk -e 's/Some/any/g' -e 's/item/stuff/g' file or you can use just one: sed -i.bk -e 's/Some/any/g;s/item/stuff/g' file You should give an extension for backup file, since when some implementation of sed, like OSX sed does not work with empty extension (You must use sed -i '' to override the original ...


0

As you can probably tell there are lots of ways to do this. Regarding your "UPDATE #2" -- generally speaking, terminating any process in a parent-child hierarchy will generally terminate all the associated processes. But there are many exceptions to this. Ideally you want to terminate the final 'child' in a process tree, then the parent(s) of this child ...


1

I don't do the whole mac thing anymore, so I don't have anything to test with, but in the quest to get this working on FreeBSD, I managed to figure out how to get this working from ports. I recall OSX has stuff like brew and macports - Try installing the GNU coreutils from this if you really want dircolors to work. I also had to set an alias for dircolors to ...


0

With awk: $ awk 'BEGIN{FS=OFS="|"}NR==FNR{a[$1]=$0;next}{$1=a[$1]}1' file_1 file_2 14595|Age 35|Salary xx|Position ax|2013|Info 1|Info 2|Info 3|Info 4|Info 5|Address xx|Info 6|Info 7|Info 8 14649|Age 30|Salary xx|Position az|2015|Info 1|Info 2|Info 3|Info 4|Info 5|Address xxxz|Info 6|Info 7|Info 8


2

Use join: $ join -t'|' file_1 file_2 14595|Age 35|Salary xx|Position ax|2013|Info 1|Info 2|Info 3|Info 4|Info 5|Address xx|Info 6|Info 7|Info 8 14649|Age 30|Salary xx|Position az|2015|Info 1|Info 2|Info 3|Info 4|Info 5|Address xxxz|Info 6|Info 7|Info 8 -t indicates the field separator. In order to join works, files must te sorted. You can use sort for ...


1

Another solution: find records -type f -iname '*.mpg' | xargs rename 5.mpg 0.mpg Since all the files that you want to rename ends with *5.mpg, this find+rename combo will work just fine for you.


0

Actually I gave a try to write my own script. It seems to work: #!/bin/bash find . -type f -iname "*5.mpg" -print0 | while IFS= read -r -d $'\0' line; do new=${line//5.mpg} zero="0.mpg" buffer=$new$zero new=$buffer mv $line $new echo "Moving $line" done


1

Just loop through all *.5mpg files and use help of parameter expansion to change filenames: for file in *5.mpg; do mv -- "$file" "${file%5.mpg}"0.mpg; done To do it for different directories set globstar option (shopt -s globstar in bash) and additionally take path component with dirname command or again using parameter expansion.


0

Pure BASH version: dir='/users/wahasan';stamp=$(date +%Y%m%d_%H%M%S); for file in $dir/CHK*.pos; do nn=${file/CHK/old/CHK}; nn=${nn/pos/pos_$stamp}; echo "$file ---> $nn";mv $file $nn; done try it, should work ED: dir='/users/wahasan'; ## path to work directory stamp=$(date +%Y%m%d_%H%M%S); ## date_time stamp for file in $dir/CHK*.pos; ...


1

Let's use AWK! $ function wordfrequency() { awk 'BEGIN { FS="[^a-zA-Z]+" } { for (i=1; i<=NF; i++) { word = tolower($i) words[word]++ } } END { for (w in words) printf("%3d %s\n", words[w], w) } ' | sort -rn } $ cat your_file.txt | wordfrequency This lists the frequency of each word occurring in the provided file. I know it's not what you asked for, ...


1

You inner shell is not interactive; remove the -i flag and it should stop freaking out. See What should interactive shells do in orphaned process groups? for an explanation of what is going on under the cover.


1

Putting a ; after a & does not work. & is already a command separator, specifying, that the command should be run in the background, so ; is not required. Try removing the ; and report back.


2

You can use the touch command to create empty files. With crazy names like that, it's essential to quote them properly. touch ";rm *;.jpg" ";rm -rf *;.jpg" If you create files named like that on my machine your life expectancy will be very short. :)


11

It's a matter of timing: bash launches the hello command in the background, then it displays a prompt to let you enter a new command, then the background command prints some output. When you enter the next command line (an empty command line, if you just press Enter), bash displays the notification that the background job has finished, then the next prompt. ...


2

The command you have above will (somewhat clumsily) rename all files in the current directly from *.jpg to *.jpeg, it could be modified to delete all files but is hardly appropriate to the task. However, it sounds like you are trying to craft a suitable filename such that when the above command encounters it, it will delete everything in the current ...


1

The following uses data.csv as a link to the requested file to keep status between iterations. # check to see if an argument is given if [ "$#" -ne 1 ]; then echo "Illegal number of parameters" exit fi # check if ran before if so move that to processed/ directory if [ -h "data.csv" ]; then prev=`readlink data.csv` echo ...


1

Linux specific: echo |perl -e '$p=getppid; `echo foo > /proc/$p/fd/2`' If you here redirect stderr 'foo' is still printed on the terminal: echo |perl -e '$p=getppid; `echo foo > /proc/$p/fd/2`' 2>/dev/null


1

If the file names have no newlines, you can find the first file to process in a bash script by using: first=$(ls --sort=version *.csv | head -1) ln -s "$first" data.csv however before you rename that file you have to make sure and old existing one is out of the way: #! /bin/bash if [ -e data.csv ] ; then mv $(readlink data.csv) backup_directory rm ...


2

You can use ps+grep or pgrep to get the process name/pid; later use killall/pkill to kill process name or use kill to kill pid. All of the followings should work. killall $(ps aux | grep script_name | grep -v grep | awk '{ print $1 }') && killall inotifywait (ps -ef | grep script_name | grep -v grep | awk '{ print $1 }' | xargs killall) && ...


1

To improve, use killall, and also combine the commands: ps -aux | grep script_name killall script_name inotifywait Or do everything in one line: killall `ps -aux | grep script_name | grep -v grep | awk '{ print $1 }'` && killall inotifywait


0

List the background jobs using # jobs Then choose the the prior number of job and run example # fg 1 will bring to foreground. Then kill it using CTRL+C or easier way to find the PID of script using ps -aux | grep script_name Then kill using pid sudo kill -9 pid_number_here


4

Just use redirection operator > at the first line: sqlplus -s "/nolog" <<EOF >logfile conn / as sysdba @?/sqlpatch/19282021/postinstall.sql exit; EOF You can also write >logfile at the beginning of the line, what is equally legal syntax in most shells, but less commonly practiced. >logfile sqlplus -s "/nolog" <<EOF conn / as ...


2

The simplest answer is to escape the [ so that it isn't treated as a special pattern character. (The closing ] is treated literally if it isn't preceded by an unquoted [.) test=$(echo \[asdf])



Top 50 recent answers are included