Reputation: 951
Trying to get more familiar with awk, and am using system command to scp a bunch of files across servers.
So I tried this, but it doesn't work. Does not error, just doesn't do anything.
ls *.dmp | awk ' {system("nohup scp "$1" username@server:/server/file/path/ &")}'
However, this works
ls *.dmp | awk ' {print "nohup scp "$1" username@server:/server/file/path/ &"}' > scp.sh && chmod +x scp.sh && ./scp.sh
Goal is just trying to execute everything that awk returns.
Upvotes: 0
Views: 237
Reputation: 10271
Solaris 10's /usr/bin/awk
doesn't have a system
function, and it will not raise an error when you make a call to an undefined function; the return value of the function will be whatever its argument is. Instead, use either /usr/xpg4/bin/awk
or nawk
.
As Glenn and Andrew pointed out, if all you need to do is run a shell command multiple times with one argument varying each time, this can be done in the shell itself without getting awk involved.
for f in *.dmp
do
nohup scp "$f" username@server:/server/file/path/ &
done
Upvotes: 3