1

I have a shell script that writes the date to a log file when executed. When I run the script manually, the correct output gets written to the file. However, this needs to be automated, and when I run as a cron job, nothing is getting written to the file and I am confused why.

crontab:

0 * * * * tomcat /usr/bin/sh /apps/rdsreplication/snap_replication.sh

Sample Code:

#/bin/bash/

echo ---------------------------------------- >> create_snap.txt
echo Start time:  >> create_snap.txt
date >> create_snap.txt

Any help would be appreciated!

AndG
  • 193
  • What working directory pwd does cron run things under? – thrig Mar 02 '17 at 17:07
  • Do you actually have a /usr/bin/sh? This is an unusual location for a shell. 2. Which crontab file are you using, or how are you adding this line to cron? 3. What gets reported in cron's log file (typically somewhere in /var/log) for this job?
  • – Chris Davies Mar 02 '17 at 17:08
  • @thrig, this is the crontab for the tomcat user, so I assume it is running out of /home/tomcat/. – AndG Mar 02 '17 at 17:10
  • 2
    @thrig it's the user account's home directory – Chris Davies Mar 02 '17 at 17:10
  • @roaima yes, on this server I ran which sh, and that was the path returned. I am using the tomcat user's crontab, I am adding the line using crontab -e. /var/log/cron shows this: Mar 1 18:06:01 sonar CROND[1585]: (tomcat) CMD (/usr/bin/sh /apps/rdsreplication/snap_replication.sh) – AndG Mar 02 '17 at 17:13
  • 1
    @roaima: many systemd-based distros have /bin as a symlink to /usr/bin nowadays, since it is no longer possible to have /usr on a separate partition anyway. – Ulrich Schwarz Mar 02 '17 at 17:19
  • @UlrichSchwarz I was thinking of Solaris (not used it for years, though) – Chris Davies Mar 02 '17 at 17:19
  • @roaima maybe. But what directory is that? NULL on account of Active Directory doing lord knows what? Flapping between what LDAP is providing and a local account, depending on the whims of sssd or such? – thrig Mar 03 '17 at 15:30
  • @thrig I don't seem to have any problems with sssd. In the configurations I use there's a template definition for users' home directories so it doesn't need to be specified in AD. However, regardless of how a user's home directory is set up, that's where the cron instance sits. It's up to the user (or sysadmin) to decide whether or not the directory should be writeable. – Chris Davies Mar 03 '17 at 15:37