LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-10-2011, 01:49 PM   #1
ScorchPipe
Member
 
Registered: Sep 2010
Posts: 38

Rep: Reputation: 0
Problems with rc.local, it wont run my bash-script at startup


Hi there.

I have some problems with rc.local. It wont execute a scipt of mine at startup.
The script itself works and if I run rc.local manually it works too...

The script to run:

#!/bin/sh

# Getting your external IP-adress from http://whatismyip.org/
set `lynx -dump http://whatismyip.org/`
IP=$1

# Specify the following options

# Senders email:
SendersEmail="mymail@hotmail.com"

# Senders usernamne:
Username="mymail@hotmail.com"

# Senders password:
Password="mypassword"

# Recievers email:
RecieversEmail="myothermail@hotmail.com"

# Subject:
Subject="IP-adress"

# Message:
Message="$IP"

# SMTP Server:
Server="smtp.live.com:587"

# Sending the email

sendEmail -f $SendersEmail \
-t $RecieversEmail \
-s $Server \
-xu $Username \
-xp $Password \
-u $Subject \
-m $Message


/etc/rc.d/rc.local:


[root@Rorschach rc.d]# cat rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

./sendIPmail.sh
[root@Rorschach rc.d]#


Doesn't seem to be a lynx-issue. I've tried with hard coded text as message too...
The script lies under / and have chmod 777.
Any ideas?

Running CentOS 5.5
(if you didn't get it, this script is for sending the external IP-adress to my email att startup. If a thief is stupid enough to start it connected to internet)

Last edited by ScorchPipe; 01-10-2011 at 01:50 PM.
 
Old 01-10-2011, 02:00 PM   #2
HasC
Member
 
Registered: Oct 2009
Location: South America - Paraguay
Distribution: Debian 5 - Slackware 13.1 - Arch - Some others linuxes/*BSDs through KVM and Xen
Posts: 329

Rep: Reputation: 55
what about using the absolute path of your script?
 
Old 01-10-2011, 02:13 PM   #3
ScorchPipe
Member
 
Registered: Sep 2010
Posts: 38

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by HasC View Post
what about using the absolute path of your script?
The absolute path is /sendIPmail.sh

I've tried other locations too.
 
Old 01-10-2011, 02:16 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 11,863

Rep: Reputation: 739Reputation: 739Reputation: 739Reputation: 739Reputation: 739Reputation: 739Reputation: 739
To expand on HasC's post the . in ./sendIPmail.sh is a shortcut for current working directory. Basically it is not running since the script can not be found. If you use the full path your script should work as expected.
 
Old 01-10-2011, 02:19 PM   #5
ScorchPipe
Member
 
Registered: Sep 2010
Posts: 38

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
To expand on HasC's post the . in ./sendIPmail.sh is a shortcut for current working directory. Basically it is not running since the script can not be found. If you use the full path your script should work as expected.
so if I put

/bin/sh /sendIPmail.sh

in rc.local for example?
 
Old 01-10-2011, 02:28 PM   #6
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, CentOS, Ubuntu, Fedora, Timesys, Linux From Scratch
Posts: 1,777
Blog Entries: 20

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by ScorchPipe View Post
so if I put

/bin/sh /sendIPmail.sh

in rc.local for example?
As long as the script really is in /sendIPmail.sh and is chmod 755 and has the "#!/bin/bash" string in line one, it should be sufficient to just do:

/sendIPmail.sh

e.g. without the /bin/sh.
 
Old 01-10-2011, 02:28 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 11,863

Rep: Reputation: 739Reputation: 739Reputation: 739Reputation: 739Reputation: 739Reputation: 739Reputation: 739
Just /sendIPmail.sh since the script is executable. Furthermore the path to lynx and sendmail may not be set until a user actually logs in so use the full path for them too.
 
Old 01-10-2011, 02:31 PM   #8
ScorchPipe
Member
 
Registered: Sep 2010
Posts: 38

Original Poster
Rep: Reputation: 0
Ok I will try it... and its sendEmail, not sendmail =)
 
Old 01-10-2011, 02:39 PM   #9
ScorchPipe
Member
 
Registered: Sep 2010
Posts: 38

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
Just /sendIPmail.sh since the script is executable. Furthermore the path to lynx and sendmail may not be set until a user actually logs in so use the full path for them too.

How do I get the full path to a program (sendEmail and lynx)?
 
Old 01-10-2011, 03:13 PM   #10
impert
Member
 
Registered: Feb 2009
Posts: 282

Rep: Reputation: 53
Quote:
How do I get the full path to a program
Code:
which sendmail
 
Old 01-10-2011, 03:41 PM   #11
ScorchPipe
Member
 
Registered: Sep 2010
Posts: 38

Original Poster
Rep: Reputation: 0
Thank you guys. It works now!
 
  


Reply

Tags
bash, centos, lynx


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
in bash shell how to run shell script during startup rammohan04 Red Hat 2 07-31-2009 02:07 AM
My Linux Bash Script Fails to run when automated with OS Startup sanitynotvanity Linux - Software 5 06-16-2009 10:50 AM
how to run a bash script before startup alirezan1 Linux - Newbie 3 01-14-2009 09:51 PM
bash - start remote script from local script? babag Programming 7 04-06-2008 05:46 PM
Startup script not working in rc.local crackerB Linux - Software 9 10-09-2006 07:55 AM


All times are GMT -5. The time now is 07:20 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration