im currently running the following command to grab all arguments in front of a script, directly from the process table.
# cat /tmp/allmyprocs
ubuntu 9933 27793 0 03:29 pts/0 00:00:00 /bin/sh ./prying.sh
ubuntu 9941 9933 0 03:29 pts/0 00:00:00 sh
ubuntu 9952 9941 0 03:29 pts/0 00:00:00 sh
myncurpid=9933
AFILENAME=prying.sh
cat /tmp/allmyprocs | awk -v JAG=9933 '$0 ~/ '${myncurpid}' / && ($2 == JAG) {print $0}' | awk -F"prying.sh" '{print substr($0,index($0,$NF))}'
which produces:
ubuntu 9933 27793 0 03:29 pts/0 00:00:00 /bin/sh ./prying.sh
Whenever there are no arguments passed to the "prying.sh" script, the above code outputs the entire line from the ps -ef command. I dont want that to happen. i dont want the entire line to be outputted whenever arguments are not passed.
In other words:
If there are no arguments passed to the script, print nothing.
If there are arguments passed to the script, print only those arguments.
my command is suppose to grab everything in front of prying.sh to the end of the line. but its not doing that.