0

When I run the following script from command line I get the full output in /tmp/Fdisk.sh.

But if I run the same script from cron I get only partial output.

Is the shell skipping some instruction when run from cron?

My Shell script:

SHELL=/bin/sh
LC_NUMERIC=en_US.utf8

/usr/bin/printf "\nm\np\nl\nq" | fdisk /dev/mmcblk0

CRON entry:

* * * * * /home/WiMi/tryFdisk.sh >> /tmp/Fdisk.txt

Output, when run from cron:

cat /tmp/Fdisk.txt

Disk /dev/mmcblk0: 63.8 GB, 63864569856 bytes
4 heads, 16 sectors/track, 1948992 cylinders
Units = cylinders of 64 * 512 = 32768 bytes

        Device Boot      Start         End      Blocks  Id System
/dev/mmcblk0p1              33     1948992    62366720  83 Linux

The main concern here is the missing of commands passed to fdisk in a non interactive way.

I have passed commands and couple of them got skipped.

m - display help screen - skipped p - print current partition table - executed l - list know partition types - skipped q - quit - executed

If I run the same script from command line, all of them gets executed and the output is seen on the /tmp/Fdisk.txt file.

RaAmir
  • 11
  • 4
  • 3
    Possible duplicate of [Why is my crontab not working, and how can I troubleshoot it?](http://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it) – user9517 Mar 04 '17 at 07:24
  • I agree the answer is in http://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it - this question does have some value in that it deals specifically with output redirection (@RaAmir, check the section on 'Debugging cron commands'), but I do think there is more value in reading through the canonical crontab answer. – iwaseatenbyagrue Mar 04 '17 at 10:45

0 Answers0