0

Works:

crontab -e
  * * * * * date >> /home/pi/scripts/test.log

Doesn't Work:

crontab -e
  * * * * * /home/pi/scripts/test.sh

test.sh

  #!/bin/hash 
  * * * * * date >> /home/pi/scripts/test.log

please tell me where problem this is my first tested raspberry :-)


/etc/init.d/cron status -l

cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled)
   Active: active (running) since Po 2016-03-21 21:27:41 CET; 15min ago
     Docs: man:cron(8)
 Main PID: 12087 (cron)
   CGroup: /system.slice/cron.service
           └─12087 /usr/sbin/cron -f

bře 21 21:40:01 rbpi CRON[13517]: pam_unix(cron:session): session closed for user root
bře 21 21:41:01 rbpi CRON[13612]: pam_unix(cron:session): session opened for user root by (uid=0)
bře 21 21:41:02 rbpi CRON[13619]: (root) CMD (/home/pi/scripts/test.sh)
bře 21 21:41:02 rbpi CRON[13612]: pam_unix(cron:session): session closed for user root
bře 21 21:42:01 rbpi CRON[13770]: pam_unix(cron:session): session opened for user root by (uid=0)
bře 21 21:42:01 rbpi CRON[13777]: (root) CMD (/home/pi/scripts/test.sh)
bře 21 21:42:01 rbpi CRON[13770]: pam_unix(cron:session): session closed for user root
bře 21 21:43:01 rbpi CRON[13865]: pam_unix(cron:session): session opened for user root by (uid=0)
bře 21 21:43:01 rbpi CRON[13872]: (root) CMD (/home/pi/scripts/test.sh)
bře 21 21:43:01 rbpi CRON[13865]: pam_unix(cron:session): session closed for user root

closed as off-topic by Jacobm001, Steve Robillard Mar 21 '16 at 21:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – Jacobm001, Steve Robillard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • For starters, what's that with all the asterikses in the shell script? – Ghanima Mar 21 '16 at 20:38
  • @Ghanima: they're modeling it after the cron call... – Jacobm001 Mar 21 '16 at 20:38
  • what is the ownership and permission of test.sh? Does the test.sh script work if called from the commandline? did you make tets.sh executable? Aslo, what is it you are trying to do? As it stands you are attempting to write the date to a log file every second? – Steve Robillard Mar 21 '16 at 20:40
2

The *s in your crontab specifies when to run the command. The *s mean to run the command at every minute, of every hour, of every day of the month, of every month, of every day of the week.

In your shell script "*" isn't something you want to specify at the beginning of the line. The asterisk means, basically, all files in the current directory, which isn't what you're trying to run for your command; you want to run date.

Remove the asterisks from your shell script.

2

There's a lot wrong with your bash script.

For starters the shebang is wrong. It should be #!/bin/bash, not #!/bin/hash.

Your other issue is including all the asterisks (*) in your bash script. They're used in the cron entry to tell it when it should be run, but cause errors in the actual shell script. Change the second line of test.sh to just date >> /home/pi/scripts/test.log.

1

Get rid of the asterisks in the .sh script, as they're only valid in a crontab.

#!/bin/bash 
date >> /home/pi/scripts/test.log

Otherwise, bash expands every single * into a list of all the files in the working directory, which isn't a valid command!

  • Yes sorry test.sh date >> /home/pi/scripts/test.log – user2851761 Mar 21 '16 at 20:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.