Quote:
Originally Posted by Habitual
show us your "code".
[code]script or code output here[/code]
Thank you.
|
OK this is a slimmed down version of what my program should do. It should collect fields 1 and 7 from the /etc/passwd file and then look for a specific user (grep $1).
It works well displaying on screen but the tee portion doesn't work completely because it only creates the file but it's not filled with the output. In my full file I had to put the | tee portion at the end of each line to make it work properly but am wondering if/hoping there is a more elegant way to do all of this in a single line.
Thanks!
CODE:
#!/bin/bash
argument=$1
DATE=$(date +"%m%d%y%k%M")
echo "TPS REPORT LISTING"
echo
awk -F':' '{print $1", " $7}' /etc/passwd | grep $1
echo
echo "END REPORT LISTING"
exec | tee -a ~/scripts/tps-list-$1-$DATE.rpt
OUTPUT:
Running the script like this: sh tps-gen.sh chris I get this on the display:
TPS REPORT LISTING
chris, /bin/bash
END REPORT LISTING
and doing an ls to the directory where the file needs to be created I can see the filename but an ls -l shows it with a size of 0:
ls
testFunction.sh tps-gen.sh tps-list-chris-0725161728.rpt
ls -l
total 8
-rwxrwxrwx 1 chris chris 220 lip 25 17:28 tps-gen.sh
-rw-rw-r-- 1 chris chris 0 lip 25 17:28 tps-list-chris-0725161728.rpt