2

I want a script on my AIX machine to be executed upon server reboot. I tried below command in my crontab file but received an error.

@reboot sleep 300 && /usr/bin/sh /opt/script.sh

A line of the crontab file: @reboot sleep 300 && /usr/bin/sh /opt/script.sh

contains the following error: 0481-079 Reached a symbol that is not expected.

ZygD
  • 22,092
  • 39
  • 79
  • 102
Aniruddha Salve
  • 101
  • 1
  • 4

1 Answers1

1

To execute a script when an AIX server reboots, you have two options, both of which involve the /etc/inittab file.

Option #1 is to insert the call to your script as an inittab entry, with mkitab; for example:

mkitab 'myscript:2:once:/opt/script.sh'

This assumes you've made /opt/script.sh executable (chmod +x /opt/script.sh) and put a proper sh-bang line in it. There's no need to prefix it with /usr/bin/sh once you've done that.


Option #2 is to leverage the existing runlevel 2 script directory, which is invoked from /etc/inittab with the l2:2:wait:/etc/rc.d/rc 2 entry. Simply place your (properly executable) /opt/script.sh file in /etc/rc.d/rc2.d named with a leading S, to indicate it should be started in runlevel 2. For example:

cp /opt/script.sh /etc/rc.d/rc2.d/S90-script.sh

Here I've prefixed it with "S90", which has the leading S to indicate startup and 90 as a rough way to sequence items within runlevel 2. The caveat to this solution is that the init system will assume that your script supports a parameter -- start or stop. During boot, it will call your script with the "start" parameter. If your existing script silently ignores any parameters, you're fine. Otherwise, you may need to modify it or write a wrapper script.

Jeff Schaller
  • 2,352
  • 5
  • 23
  • 38