
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tlug] question about shell scripting
On 25/01/07, scott@example.com <scott@example.com> wrote:
I would like to list all of the crotabs for all of the users in the system.
So first I get a list of users:
awk -F: '{ print $1 }' /etc/shadow
I would advise hitting /etc/passwd instead of /etc/shadow, just
because it feels more right.
which is OK. However if I want to use backticks and do something like this:
crontab -l -u `awk -F: '{ print $1 }' /etc/shadow`
This is equivalent to:
crontab -l -u user1 user2 ... userN
Try feeding two usernames to crontab on the command line and see what happens.
I thought maybe I could write a for statement in a script this way:
#!/bin/bash
for x in `awk -F: '{ print $1 }' /etc/shadow`;
/usr/bin/crontab -l -u $x;
done
Close, but no cigar. You left out on minor word that would have made
everything work: "do". Dig this:
for x in `awk -F: '{ print $1 }' /etc/shadow`; do
/usr/bin/crontab -l -u $x;
done
I added indentation to be nice.
HTH,
Josh
Home |
Main Index |
Thread Index