Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Sorry for the newb question but I'm not a strong scripter by any means. I have a simple bash script that i created that runs perfectly fine when executed manually. Also if i run "/etc/rc.local" manually it will execute the script fully! My problem is that rc.local from boot will not execute the entire script and im having troubles determining why.

Here's the script:

#!/bin/bash

# Retrieve instance ID from metadata
GET http://169.254.169.254/latest/meta-data/local-ipv4 > /metadata

# Replace Hostname in zabbix.conf with instance ID from metadata
sudo sed -i "s/td1wb-b01/$(cat metadata)/g" /etc/zabbix/zabbix_agentd.conf

# Replace Hostname with instance ID from metadata
sudo hostname $(cat metadata)
sudo sed -i "s/web2/$(cat metadata)/g" /etc/sysconfig/network

# Restart the zabbix agent to register
sudo service zabbix-agent restart

exit 0

It seems to start running since I DO see the /metadata file appear. After that first line though, nothing else is executing. Any help is greatly appreciated!!

Thank you

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Your script calls 'sudo' to gain extra privileges. Sudo requires that you interactively log in, or that the user calling it has recently used sudo interactively. Remove sudo and you should be fine as long as the script itself is run as root.

share|improve this answer
    
YOU GUYS ARE AWESOME!!!!! I cant believe it was that simple lol...learn something new every day!! Thank you very much! –  Nick Hatfield Oct 2 '13 at 13:30

You should remove the sudo, rc.local is run by root anyway.

share|improve this answer
2  
That, plus it might that sudo is not passing env var like PATH, also has tty required enabled. Depends on the distro. –  Danila Ladner Oct 2 '13 at 1:49
    
YOU GUYS ARE AWESOME!!!!! I cant believe it was that simple lol...learn something new every day!! Thank you very much! –  Nick Hatfield Oct 2 '13 at 13:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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