Misc Linux/Unix commands

********** commands/scripts I’ve run *********
foreach j ( `echo */*.rpm ` )
foreach? rpm -qilp $j | grep -q local
foreach? if ( “$status” == 0 ) echo $j
foreach? end

*************
which acroread > /dev/null 2>&1

*************
ARCODIR=`which acrorea 2> /dev/null`

*************
# Fix perl symlink in /usr/local/bin if
# /usr/local is not a link and does not already exist.

if [ ${USRLOCAL} = 0 -a ! -f /usr/local/bin/perl ];
then
echo “Linking /usr/bin/perl to /usr/local/bin/perl”
ln -s /usr/bin/perl /usr/local/bin/perl
else
echo “Either /usr/local is a link or /usr/local/bin/perl exists”
fi

*************************
#Makes cool rotating wheel on screen.

clear; count=100; while [ $count -gt 0 ]; do echo ‘/’; sleep 1; count=`expr $count – 1`; clear; echo ‘-‘; sleep 1; count=`expr $count – 1`; clear; echo ‘\’; sleep 1; count=`expr $count – 1`; clear; echo ‘|’; sleep 1; count=`expr $count – 1`; clear; done

*************************
#Show the network devices installed and all relavant data.
cat /etc/sysconfig/hwconf | awk ‘BEGIN{RS=”-“} ; /NETWORK/{print $n }’
cat /etc/sysconfig/hwconf | awk ‘BEGIN{RS=”-“};/NETWORK/{print $n }’ | awk -F” ” ‘$1 ~ /desc|pcibus|device/ { print $n }’

************************
#display from ypcat hosts a specific set of machine names minus a list of exclusions.

ypcat -k hosts | grep tstpsoc | awk -F” ” ‘$1 !~ /tst.test.com|fh|fil|dev/ { print $1}’ | sort -n

*********************
foreach j (`cat /tmp/tstpsoc.txt`)
foreach? echo “$j **********”
foreach? rsh $j cat /etc/sysconfig/hwconf | awk ‘BEGIN{RS=”-“};/NETWORK/{print $n }’ | awk -F” ” ‘$1 ~ /desc|pcibus|device/ { print $n }’

**************
for bash shell foreach
for j in `cat /tmp/tstpsoc.txt`; do echo $j; done

**********************
#show current gateway RHEL:
/sbin/route -n | /bin/awk ‘/UG/ {printf ($2);exit}’
*********************
bash of sh
#Convert a hex variable to decimal
#16 for hex, 8 for oct, 2 for bin.
#n should be number to convert

decval=$((16#n))

****************
#Bash or sh in rhel3:
#check NICS and compare to see how devices are setup and what pcibus
#they are installed.

NIC0d=$((16#`cat /etc/sysconfig/hwconf | awk ‘BEGIN{RS=”-“};/eth0/{print $n }’ | awk -F” ” ‘$1 ~ /pcibus/ { print $2 }’`))

NIC1d=$((16#`cat /etc/sysconfig/hwconf | awk ‘BEGIN{RS=”-“};/eth1/{print $n }’ | awk -F” ” ‘$1 ~ /pcibus/ { print $2 }’`))

if [ ${NIC1d} -gt ${NIC0d} ];
then
echo true;
else
echo false;
fi

***********

#Local rsync command, like a robust copy:
rsync -avz /src/foo/ /dest/foo
*****************

for linux to disable or enable services via a script:
DSNSRVC=”telnet rexec”
for i in ${DSNSRVC} ; do
[ -f /etc/rc.d/init.d/$i -o -f /etc/xinetd.d/$i ] &&
echo -n “Disabling $i…” &&
/sbin/chkconfig –del $i &&
/sbin/chkconfig –list $i &&
echo ” Done.”
done

ENSRVC=”rsh rlogin kudzu”
for i in ${ENSRVC} ; do
[ -f /etc/rc.d/init.d/$i -o -f /etc/xinetd.d/$i ] &&
echo -n “Enabling $i…” &&
/sbin/chkconfig –add $i &&
/sbin/chkconfig –list $i &&
echo ” Done.”
done
*****************
foreach j (`awk ‘BEGIN {FS=” “; ORS=”\n”} {print $2,$3,$4}’ /home/<user>/brkdwn.txt`)
foreach? ypp $j

*************
AWK:

#Passing a varible inside an awk statement:
varibale is enclosed by single, then double quote: ‘”$VARIABLE”‘
#example:
cat /etc/sysconfig/hwconf | awk ‘BEGIN{RS=”-\n”};/'”$INFO”‘/{print $n}’

****************
sed commands for substituting after a certain string”
sed ‘s/\(search_string\).*/\1new.data_after_search_striung/’ file_to_mod
sed ‘s/\(IPADDR=\).*/\1new.ip.addr/’ tmp/new_eth1

********************
#Find Serial number on Linux Systems:
dmidecode | awk ‘BEGIN{RS=”Handle”;} /Chassis/{print $n}’

########
#to find all mouse types in XFreeConfig to fix nVidia BS.

cat XF86Config.save | awk ‘BEGIN{RS=”Section”};/mouse/{print $n}’

###########
#to show only current working directory and not path:
pwd | awk -F”/” ‘{ print $NF }’
###########
#Check and anser and current directory to do something.
/bin/sh
if [ ${ANSR} = “y” -a `pwd | awk -F”/” ‘{ print $NF }’` = “SmarTest” ]; then echo go; else echo no; fi

################
#Piece from NIC fix in Verigy script sed commands:

sed ‘s/eth0/eth1/’ /tmp/ifcfg-eth0.orig | sed ‘s/ONBOOT=no/ONBOOT=yes/’ | sed ‘s/\<NETWORK=/#&/’ | sed ‘s/\<BROADCAST=/#&/’ > /etc/sysconfig/network-scripts/ifcfg-eth1;

sed ‘s/\<NETWORK=/#&/’ | sed ‘s/\<BROADCAST=/#&/’

cat XF86Config.orig | awk ‘BEGIN{RS=”Section”};/mouse/{print $n}’ | sed ‘s/ “InputDevice”/Section “InputDevice”/’ | sed ‘s/End/EndSection/’ | sed ‘s/^/#&/’

cat XF86Config.nvidia | awk ‘BEGIN{RS=”Section”};/mouse/{print $n}’ | sed ‘s/\”PS\/2\”/ \”IMPS\/2\”/’
cat /etc/sysconfig/hwconf | awk BEGIN'{RS=-}/NETWORK/&&/’eth1’/ { print | grep network.hwaddr }’
ypcat -k hosts | awk ‘$1 ~ /vng/&& $1 !~ /tst.test.com/ { print $1 }’

################
#Find Duplex connections status/setting:
#Solaris:
dmesg | awk ‘BEGIN{RS=”\n”;FS=” “;} /hme/&&/Duplex/ { print $4,$5,$9,$11,$12,$13 }’ | uniq
dmesg | awk ‘BEGIN{RS=”\n”;FS=” “;} /hme/&&/Duplex/ { print $n }’ | uniq

#Linux:
dmesg | awk ‘BEGIN{RS=”\n”;FS=” “;} /eth/&&/Duplex/ { print $n }’
#####
#Find disk space at either build or boot when only /proc is available and no partitioning has been done and covert to MB:

hdsize=$((`cat /proc/ide/hda/capacity | cut -d= -f2` / 2048 ))

#################
rsync to exclude all version except the one given, including subdirectories.

rsync -rpvlt -nvP –include “*5.4.2*/” –exclude “*[4-5].*/” tfladm.test.com::Verigy_SmarTest/ .

####

#Check UID file against vcde function to find valid unused UID.
/bin/sh

for j in `cat uidfile` ; do if [ ! `/nfs/adm/bin/vce.accts -i $j` ]; then echo “$j is not used”; else echo “$j is already in use”; fi; done

###############
#list all invalid links and print out the link name only and save to file
ls -L | & egrep ls: | & awk -F”: ” ‘{ print $2 }’ > /tmp/links

#################
#Manually encryt password:
openssl passwd <password>
openssl passwd -1 -salt “tlas” <password>
################
#Create a large file fast and without actually writing data to the file
fallocate -l 10G gentoo_root.img
#fallocate is the final — and best — choice for use with VM disk allocation, because it essentially “reserves”
#(or “allocates” all of the space you’re seeking, but it doesn’t bother to write anything.
#So, when you use fallocate to create a 20 GB virtual drive space, you really do get a 20 GB file
#(not a “sparse file”, and you won’t have bothered to write anything to it —
#which means virtually anything could be in there — kind of like a brand new disk!)

 

 

 

 

Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.