Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] question about shell scripting



On Thu, 25 Jan 2007, scott@example.com wrote:

So first I get a list of users:

awk -F: '{ print $1 }' /etc/shadow

In general, you'd want to use /etc/passwd; isn't /etc/shadow readable only by root? Though it probably doesn't matter in this case, since you no doubt need to be root to run your particular script.

which is OK. However if I want to use backticks and do something like this:

  crontab -l -u `awk -F: '{ print $1 }' /etc/shadow`

it crashes. I'm guessing that the output of that awk is a stream instead
of a list of individual names with a line break.

It's a list of names separated by whitespace.

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

You forgot a do, from the looks of it. This works for me:

    for i in $(awk -F: '{print $1}' /etc/passwd); do
	echo $i
    done

cjs
--
Curt Sampson       <cjs@example.com>        +81 90 7737 2974


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links