Find if host is ssh'able or not:
#!/bin/bash
i=`traceroute $1 | grep -v "traceroute to" | grep -c $1`
##echo $i
if [ $i -eq 1 ];
then
echo " $1 Host is SSH'able";
else
echo " $1 Host is not SSH'able";
fi
Find if host is pingable or not.
Solution1:
for host in host1 host2 ; do ping -c2 $host >/dev/null && echo $host is up || echo $host is down; done
Solution2:
ping -c 1 "$1" > /dev/null
if [ "$?" -eq 0 ] ; then
echo "$1 Host is up"
else
echo "$1 Host down"
fi
Solution3:
#!/bin/bash
HOSTS=" $1 $2 $3 $4"
COUNT=4
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{print $2}' | awk '{print $1}')
if [ $count -eq 4 ]
then echo "$myHost is up!"
else echo "$myHost is having ping issues!"
fi
done
Sed command usage:
% _now="$(sed -e 's/\//_/g;s/:/_/g' <<<$(date +'%D_%T'))"
% echo $_now
02_08_12_15_49_26
% _now=$(sed 's/[\/:]/_/g' <<<$(date +'%D_%T'))
% echo "$_now"
Move error files generated by find command to /dev/null:
find / -name cat.txt -print 2>/dev/null
Negation of a particular file type:
$ find ./temp/* ! -name cat.txt -print 2>/dev/null
Remove files from a directory:
find ./temp/* ! -name cat.txt -exec rm -f {} \;
Move files from one directory to another:
find ./Test1/* -exec mv {} ./temp/ \;
tr command usage:Most useful command
who | tr -s ' ' | cut -d ' ' -f3 | tr '-' '/' |tr -d '/'
tr command to count frequency of words in a document:
tr ' ' '\n' < user4 | sort | grep -v ^$ | uniq -c
To print only the frequency of characters and number in the file
tr ' ' '\n' < user3.txt | tr -cd "a-z A-Z 0-9 \n" | sort | grep -v ^$ | uniq -c
Print multi-column to single column and Single column to multi-column:
tr ' ' '\n' < user3.txt | tr -cd "a-z A-Z 0-9 \n" | sort -nr | grep -v ^$ | uniq -c |pr -t -5
^$ is a special regex that represents white row.
How do you create a file in UNIX
using touch command
using cat command
No comments:
Post a Comment