0

Want to apply this to crontab:

crontab -l > nopass
echo 'ALERT - Found a user without password on:' `hostname` `date` | cat /etc/shadow | awk -F: '($2==""){print $1}' | mail -s "Alert: Found a user without password on `hostname` `who | awk '{print $6}'`" $ADMIN_MAIL >> nopass
crontab nopass
rm nopass

But this long line is not applied. Is it because the structure of the string is wrong or is it because crontab has some kind of limit in characters? Maybe there is a more convenient way to do what I want?

2
  • 1
    Maybe you should explain what you want.
    – Teun Vink
    Commented Jan 12, 2016 at 15:58
  • ...moreover who | awk '{print $6}' if you have an user with 100 xterm opened it will be give you 100 lines for the same user (that you do not print because is in the 1st field), if it is from console you will have 100 empty lines. Why didn't you put your long line in a multi line sh or bash script and you call it from cron? If you mind, give a look here and even more here...
    – Hastur
    Commented Jan 25, 2016 at 10:08

1 Answer 1

1

There's at least one problem with your 'long line':

echo 'ALERT - Found a user without password on:' `hostname` `date` | cat /etc/shadow

The output of the echo command will be lost.

Your code would really benefit from splitting things up in multiple separate statement/lines.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .