Tag Info

New answers tagged

0

Bring the mountain to mohammed? ssh user@remote "sudo scp -r user@local:/path/to/files /opt/bin" It seems like that is a whole lot of privilege with nary a password to be seen, which would make me nervous.


0

Pipe a "sed": script.sh | sed "s|^|$('date') :: |" >> /var/log/logfile


0

Setting setproctitle_enable=YES in your vsftpd.conf file will toggle the display of session information in the process name: ftpsecu+ 27496 27479 4 13:16 ? 00:00:00 vsftpd: 2.2.2.2: connected username 27500 27496 0 13:16 ? 00:00:00 vsftpd: 2.2.2.2/username: IDLE When set to NO (the default), the UID of child processes handling the ...


0

Using "rm -rf" has an inherent race condition, you could namely delete files that were just created between the rsync and the rm invocations. I prefer to use: rsync --remove-source-files -a server:incoming/ incoming/ && ssh server find incoming -type d -delete This will NOT remove the directories if they are not empty.


0

I recommend using https://github.com/gsauthof/cgmemtime. cgmemtime measures the high-water RSS+CACHE memory usage of a process and its descendant processes. To be able to do so it puts the process into its own cgroup. For example process A allocates 10 MiB and forks a child B that allocates 20 MiB and that forks a child C that allocates 30 ...


0

You can use one option multiple times and collect results in the array: ./shell.sh -d db1 -d db2 Code: while getopts "d:" opt do case ${opt} in d) dbs+=("$OPTARG");; esac done


0

No. But you pass a single argument joined with, for example, a colon; or quoted ./shell.sh -d db1:db2 ./shell.sh -d "db1 db2" In the first case: while getopts d: opt; do case $opt in d) IFS=: read -a dbs <<< "$OPTARG" ;; esac done In the 2nd case (quoted) d) set -f # turn off filename expansion ...


1

The awk snippet works for extracting the different parts, but you still need to know which section is the key / cert / chain. I needed to extract a specific section, and found this on the OpenSSL mailinglist: http://openssl.6102.n7.nabble.com/Convert-pem-to-crt-and-key-files-tp47681p47697.html # Extract key openssl pkey -in foo.pem -out foo-key.pem # ...


0

When specifying the date and time in ISO 8601 format, you need to append a Z if you want to force it to be handled as UTC: $ date -d "1970-01-01T00:00:00Z" "+%s" 0 Alternatively, you can use a UTC offset of either +0 or -0 instead of Z.


1

if $TZ is unset and /etc/localtime is UTC then why are you using timezone T (Tango) in the date command? On my system I have a localtime of EDT. # date Wed Mar 18 12:39:03 EDT 2015 # date -d "1970-01-01 00:00:00" "+%s" 18000 If I force it to Tango then I get a negative number: # date -d "1970-01-01T00:00:00" "+%s" -25200 If I change my timezone to ...


1

Keep it simple. Diff returns 1 on difference and 0 on no difference. Use an if statement. This is how you can tell the difference between two files if diff file1 file2 > /dev/null then echo "No difference" else echo "Difference" fi To fix up YOUR problem (in which you are comparing the different between two variables in the example above use ...


1

if you want to print the lines, you need to use while read line using while read you will read line by line, for example: while read line;do echo $line ;done < /etc/passwd


3

You can also use cmp. From the man page - cmp - compare two files byte by byte. It exits with 0 if the files match. if cmp -s "$oldfile" "$newfile" ; then echo "Nothing changed" else echo "Something changed" fi


0

I can't follow your code, but the command I typically use is cd $DIR_WITH_ONE_FILE if (cd $DIR_WITH_OTHER_FILE ; md5sum $FILE) | md5sum -c --status then echo "same" else echo "different" fi It depends on the two files having the same name but living in different directories. YMMV.


0

Could it be your first variable contains the command as string, not its return value. I think you forgot the ` around the command in variable 1.


0

The fundamental problem is that Bash only supports integer arithmetic. You can work around this by using a tool which supports floating point, which conveniently Awk does. (I would also factor out the useless cat and note that sed | awk is similarly useless.) awk -v max="$max_load" '$1 > max { print "check is " $1 " and max is " max }' ...


1

There may be a third-party tool for this, but natively Linux doesn't support something like this. However, you can simply prevent any user but the owner from changing the file. Just set the chmod of the script to 755 (full access for the owner, read/execute for all others). You can compare this to most of the files in "generic" folders like /bin, they all ...


0

Thanks all, the final solution which works well on my Debian system was this, essentially converting it to an int first then using -gt. #!/bin/bash check=`cat /proc/loadavg | sed 's/ / /' | awk '{print $1}'` checkint=${check/\.*} max_load='20'; high_load_log='/var/log/apache2/apache_high_load_restart.log'; apache_init='/etc/init.d/apache2'; if [ $checkint ...


2

This isn't going to work. The > operator inside [[ compares the sort order, not the value. So.... $ echo -e '4.68\n15.00'|sort 15.00 4.68 ... because 4 sorts after 1, which means [[ 4.68 > 15.00 ]] is true. And you can't use -gt, because that requires integers. If you only care about integer thresholds, that's the easy fix — truncate at the ., use ...


0

According to the docs, the <, and > are a lexical sort. I am not certain, but I am pretty sure this is the same as what you would get if you used something like sort. With sort, 15.00 is before 4.68 because it basically sorts character by character. So 1 is before 4 in most locales. Since your example value 4.68 would be after 15.0 sorted ...


0

That is from the Documentation SOME_VAR=1 command produces an error: Unknown command "SOME_VAR=1". Use the env command. env SOME_VAR=1 command You can also declare a local variable in a block and that would not bypass the shell begin set -lx SOME_VAR 1 command end


0

Somehow simple, but finally I found the answer. This is what I did: With the help of an answer to another question at StackOverflow I redirected the whole output of the script to a file and realized that the environment variables for authentication didn't get sourced. Why: Because the shell didn't know the source command. Why? Because I was stupid enough ...



Top 50 recent answers are included