1838063 Members
5608 Online
110124 Solutions
New Discussion

cron

 
mtang
Occasional Contributor

cron

I want to submit task by crontab. When the command exceed one line, it doesn't work by using %. Can anyone present one cron sample file which one command exceed one line?
4 REPLIES 4
Matthew_50
Valued Contributor

Re: cron

simply, you can pack your task into a shortname shell script, then submit by crontab.
Muthukumar_5
Honored Contributor

Re: cron

You can try with example as,

* * * * * echo "hai" | awk '{ print $1 }' | sed 's/ //g' | awk '{ print $1 } | wc -l | awk '{ print $1 }' | sed 's/ //g' | awk
'{ print $1 }' 1>>/tmp/test.log 2>&1


Is this you want or want to execute two commands one by one.

If so then try as,

* * * * * echo "hai";who 1>/tmp/test.log 2>&1

It is always better to put this one shell script and give execution permission. IT will be executed and log file is updated.

hth.
Easy to suggest when don't know about the problem!
Fabio Ettore
Honored Contributor

Re: cron

Hi,

I think it's difficult to see this problem because a script usually can be created to customize commands and operations. Then insert the script in the sixth column of the crontab.

Best regards,
Fabio
WISH? IMPROVEMENT!
Ralph Grothe
Honored Contributor

Re: cron

Is it that what you intended?
It says that anything following an unascaped % will be sent to command's stdin
(similar to a here file, I would gather).

If your command line gets that long that it is getting hard to read I'd say it's time for a wrapper script as the others have replied.
Also think about your poor fellow admins
(probably some DBA who are not too familiar with Unix Shell "line noise") who require to comprehend your cronjobs in your absence.
Madness, thy name is system administration