4

I have a CentOS Server. When the server Boots up I want to execute a command after 10 minutes of booting up. How can I do so?

$ /usr/bin/curl -u admin:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop HDFS via REST"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}' http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services/HDFS
  • Related to http://unix.stackexchange.com/questions/57852/crontab-job-start-1-min-after-reboot if not even a duplicate. – phk Oct 16 '15 at 12:36

3 Answers3

6

You can do this in cron too. Just add in /etc/crontab:

@reboot /bin/sleep 600 && COMMAND
garethTheRed
  • 33,957
Arkon-v
  • 159
  • 3
3

try to write in a shell run at boot

at now +10 minutes <<EOF
/usr/bin/curl -u admin:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop HDFS via REST"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}' http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services/HDFS
echo hello curl > /tmp/curl.log
EOF
  • a good place, is at the end of /etc/rc.local, or /etc/rcX.d if your are more familiar with run-level.
  • creation time of /tmp/curl.log will tell you if curl ran.
Archemar
  • 31,554
0

If you're running CentOS 7, you can also use systemd timer units (see man systemd.timer). In particular, here, you can use the OnBootSec= directive.

Tom Hunt
  • 10,056