#!/bin/bash if [ $# -ne 1 ] then echo "Usage: $0" exit 0 fi host=$1
If no hostname is specified output will be:
./1.myscript.bash Usage: ./1.myscript.bash
* use my tips at your own risk !!
#!/bin/bash if [ $# -ne 1 ] then echo "Usage: $0" exit 0 fi host=$1
If no hostname is specified output will be:
./1.myscript.bash Usage: ./1.myscript.bash
I tested this on LINUX
Use as you please.
# date Mon May 18 16:16:29 EDT 2015 # date '+%s' -d "now" 1431980193 # date '+%s' -d "May 18 2014" 1400385600 # echo $(( (1431980193 - 1400385600) / 86400 )) 365
I have only seen this on solaris
# crontab -e 446
simple fix
# export EDITOR=vi
Handy gsub examples:
Removing the trailing % in the 5th field.
# echo "1 2 3 4 85%" | awk '/%/{gsub( /%/," ",$5); print}' 1 2 3 4 85
# echo "1 2 3 4 85%" | awk '/%/{gsub( /%/," ",$5); print $5}' 85
# echo "1 2 3 4 85%" | awk '/%/{gsub( /%/," ",$5); print $5","$2}' 85 ,2
# echo "1:2:3:4:85%" | awk -F: '/%/{gsub( /%/," ",$5); print$5","$2}' 85 ,2
Need to remove white spaces?
# echo "1: 2 :3:4:5:6" | awk -F: '{print $2}' 2
# echo "1: 2 :3:4:5:6" | awk 'BEGIN{FS=OFS=":"}{gsub(/^[ \t]+/,"",$2);gsub(/[ \t]+$/,"",$2)}1' 1:2:3:4:5:6
# echo "1: 2 :3:4:5:6" | awk 'BEGIN{FS=OFS=":"}{gsub(/^[ \t]+/,"",$2);gsub(/[ \t]+$/,"",$2); print $2}' 2
Same as above but print specific fields.
This post was based on the following stockoverflow.com question:
http://stackoverflow.com/questions/20600982/remove-leading-and-trailing-space-in-field-in-awk
I was getting the following error when a script was being executed via cron.
Host key verification failed. lost connection
But when the script was executed manually from the command line it worked without any issues.
* This worked for me in my particular case. This may not work in every case.
I added the following statements to the script and then ran it from cron.
which scp which ssh
The output from the two which commands :
/usr/bin/scp /usr/bin/ssh
What this told me was that the PATH I set in my cron script was forcing the script to use the scp and ssh commands in /usr/bin.
When I ran the same commands from the command line it became clear that it worked without any issues using ssh and scp in /usr/local/bin.
# which ssh;which scp /usr/local/bin/ssh /usr/local/bin/scp
My fix was to specify which scp and ssh the script should use.
Before:
scp ssh
After:
/usr/local/bin/scp /usr/local/bin/ssh