wagoneers.com



 note: most of these commands are for HP-UX 


things to do with awk

check user id's and home directories

cat /etc/passwd | awk -F: '{print $3" " $6}' | sort > sorted.pass.3.6

sort a password file in NIS

cat /var/yp/passwd | awk -F: '{print $3" "$6" "$1}' | sort

look for a process and kill it


# looking for specific string in process, e.g. dial (from a failed ppp)
ps -ef | grep dial | awk '{print "kill " $2}' 

IF IN A SCRIPT (pass it via a file):
ps -ef | grep dial | awk '{print "kill " $2}' > /tmp/killproc
sh /tmp/killproc 


SET DISPLAY in .profile (tested on Sun and HP)

who am i -R | tr -d [\(-\)] | awk '{print $NF}' | grep -v :0 | \ 
 	awk '{print "export DISPLAY="$1 ":0"}' > /tmp/setdisplay
. /tmp/setdisplay
/usr/bin/env | grep DISPLAY

NOTE:  ALWAYs look at Display setting, especially if you're moving
around and logging in and through other systems!  When using xterm
or other GUI tools, always launch with an ampersand (&) at the end
so you're able to kill it from jobs.  (jobs lists the processes
running in the background, kill %# - #=job number)

(HP-UX 11i on an 800 series wanted env fully resolved /usr/bin/env)

test login against current userid

if [ `who am i | awk '{print $1}'`=`whoami`] 
then 
blah;blah 
exit;exit 
fi 
 

more real life examples


to change user "luser"'s group from "lgroup" to "othergrp" 
 -----------------------------------------------------
root@server [/home/files]

ll | grep luser | grep lgroup | awk '{print "chown luser:othergp" " " $9}' > list
chmod 700 list
./list




test to force an su login

case `/usr/bin/who am i | awk '{ print $1 }'` in
    userid)  if [ `/usr/bin/who am i | awk '{ print $1 }'` = `/usr/bin/whoami` ]
                then
                echo "################no#login#########################"
                exit;exit
                fi;;
esac


NOTE:  userid is login name that can not login directly

root-#->HOW-TO-CLEAR-A-USER

# handy way to clear dead sessions and ALL activities of a user
#  or a process.  Puts the kill on each line.
#
# ps -ef | grep userid > nuke.userid
# cat nuke.userid | awk '{ print "kill -9 " $2 }' > nuke
# more nuke
# sh nuke

# w

to view a specific field

awk -F: '{ if ($2 == "") print $1 }' /etc/passwd awk -F: '{ if ($3 == 0) print $1}' /etc/passwd

find all files and other stuff

/usr/bin/find / -user root -perm -4000 -print | tee -a /root/suid.files (also: can use ncheck to check for suid or /dev/kmem to check perms /etc/securetty - restricts root login COPS - Computer Oracle & Password System strings may be used to view files Tripwire)

an odd ball task solved by AWK

THE PROBLEM:

I had a bunch of email addresses from a recent microslop virus problem that I needed to sort out onto one line each. I tried to replace the comma separator with a newline using sed within vi, and at the command line with little success. Didn't have my Perl notes with me, so, I worked it this way, convoluted as it may be... ;)

the solution

cat emails | awk -F , '{print $1}' > email1 cat emails | awk -F , '{print $2}' > email2 cat email2 >> email1 mv email1 list-o-emails

wagoneers.com




Select pages from WAGONEERS.COM: 

the Full Size Jeep decal! © 1998-2000 John Meister
Buy this FSJ decal...   ...use PayPal to pay for it!
Make payments with PayPal, or sign up here!


a viable option to bloated and unstable code


AMSOIL synthetic lubricants and filters
(please use customer #283461)

Independent Lifetime Dealer John Meister - customer #283461 - since 1983


Shop AMAZON.com from wagoneers.com! 
Search:
Keywords:
SHOP from wagoneers.com: in Association with Amazon.com



these pages protected by US Copyright laws
John Meister copyright © 1995-2001 all rights reserved
contact john-at-wagoneers.com
"Join the fight against spam (UCE)! Eliminate spam!" Washington State has a $500 fine for "spam"
(unsolicited commercial email)!


this is an approved Family-Friendly Site       read the Bible