Razzlerock Posted November 7, 2012 Share Posted November 7, 2012 Hi guys, I'm pulling my hair out with this! I have a simple script (see below) to send an email; root@Pineapple:/usb/etc/ssmtp# cat send-email.sh ssmtp destinationemailaddress@test.com < /usb/etc/ssmtp/email-content root@Pineapple:/usb/etc/ssmtp# cat email-content To: destinationemailaddress@test.com; From: myemail@gmail.com; Subject: Pineapple has dialed home successfully; A check has confirmed you have dialled home. root@Pineapple:/usb/etc/ssmtp# If I launch this myself from the command line (see below), it works and I get an email; root@(none):~ $ /etc/ssmtp/send-email.sh root@(none):~ $ If I add to cron (see below) and reboot, the email is never sent! root@(none):~ $ cat /etc/crontabs/root */2 * * * * ./ssh-keepalive.sh */2 * * * * /etc/ssmtp/send-email.sh root@(none):~ $ The above should send an email every 2 minutes (I am using the 2 minute interval purely for testing). Can some PLEASE help me? Its driving me mad, surely it is simple? Thanks Razzlerock Quote Link to comment Share on other sites More sharing options...
digininja Posted November 7, 2012 Share Posted November 7, 2012 Try giving it the full path to ssmtp in the script Quote Link to comment Share on other sites More sharing options...
Razzlerock Posted November 7, 2012 Author Share Posted November 7, 2012 The full path to the script is there - /etc/ssmtp/send-email.sh ? Or do I mis understand you? Thanks for the help, look forward to hearing from you. Quote Link to comment Share on other sites More sharing options...
digininja Posted November 7, 2012 Share Posted November 7, 2012 Change this: ssmtp destinationemailaddress@test.com < /usb/etc/ssmtp/email-content to <full path>/ssmtp destinationemailaddress@test.com < /usb/etc/ssmtp/email-content Quote Link to comment Share on other sites More sharing options...
Razzlerock Posted November 7, 2012 Author Share Posted November 7, 2012 Excellent, thanks - it worked. Good man! The next problem, it looks like OpenWRT does not support '@reboot' in cron; root@(none):~ $ cat /etc/crontabs/root */2 * * * * ./ssh-keepalive.sh @reboot /etc/ssmtp/ssh-check.sh What are you thoughts? I have a 'sleep 360' in /etc/ssmtp/ssh-check.sh to give the SSH tunnel time to connect. Man, i feel so close to getting this working. Quote Link to comment Share on other sites More sharing options...
digininja Posted November 7, 2012 Share Posted November 7, 2012 When exactly do you want the script to be ran? I've got some ideas but need to know that first. Quote Link to comment Share on other sites More sharing options...
Razzlerock Posted November 7, 2012 Author Share Posted November 7, 2012 First, thanks man I appreciate the help - I spent a lot of time and effort trying to get this going. I simply want to run a script to run 5 minutes after it has booted. This will give the autossh time to connect. My script will then check if the ssh has connected, and if so send an email. I don't simply want to check every x minutes and send an email. Just one email after 6 minutes of power on is suffice. I hope this makes sense :-) Quote Link to comment Share on other sites More sharing options...
digininja Posted November 7, 2012 Share Posted November 7, 2012 There may be a better way to do this but this will work... /tmp is cleared out on a reboot so have a script run every 5 mins. The script checks if /tmp/email_lock exists. If it doesn't then it creates it, sleeps for a while (long enough for the tunnel to come up) then sends the email. From then on every 5 mins the script will run but as the lock file exists it will just terminate. You could put the lock in /var/<something>, you just need to find the one that other apps use for locks under openwrt. Quote Link to comment Share on other sites More sharing options...
Razzlerock Posted November 8, 2012 Author Share Posted November 8, 2012 As I expected, the fix was right under my nose Of course, you can put startup commands in /etc/rc.local ! I did this, with a sleep 360 (6 minutes) in the .sh to allow the SSH tunnel to setup properly and hey presto it works a charm. root@(none):~ $ cat /etc/rc.local # Put your custom commands here that should be executed once # the system init finished. By default this file does nothing. /etc/ssmtp/ssh-check.sh exit 0 root@(none):~ $ Thanks digininja, you certainly helped me on the road to get this working - appreciate it man. Quote Link to comment Share on other sites More sharing options...
Sebkinne Posted November 8, 2012 Share Posted November 8, 2012 As I expected, the fix was right under my nose Of course, you can put startup commands in /etc/rc.local ! I did this, with a sleep 360 (6 minutes) in the .sh to allow the SSH tunnel to setup properly and hey presto it works a charm. root@(none):~ $ cat /etc/rc.local # Put your custom commands here that should be executed once # the system init finished. By default this file does nothing. /etc/ssmtp/ssh-check.sh exit 0 root@(none):~ $ Thanks digininja, you certainly helped me on the road to get this working - appreciate it man. I have a feeling you messed something else up along the way though. 1. root@(none) is always bad. 2. There should already be something inside the rc.local file that you should not touch. You can paste things below there though. Comments inside will help. Quote Link to comment Share on other sites More sharing options...
Razzlerock Posted November 8, 2012 Author Share Posted November 8, 2012 Hey Seb. Its OK, I did this on a TP-Link running OpenWRT. To save messing up my one and only pineapple, I use the TP-Link WR703N purely for testing. Once I am happy that I have something working on there, I apply it to the pineapple. Although the two are not identical, I have found that the majority of the time stuff that works on the TP-Link also works on the pineapple (if it doesn't work, I know its something specific to the pineapple build/implementation). Hope this makes sense. P.S. Maybe I should buy a second 'test' pineapple.... B) Quote Link to comment Share on other sites More sharing options...
PineDominator Posted November 8, 2012 Share Posted November 8, 2012 I had similar problems running commands in a .sh script for packages installed on usb, here is what i did to fix. I run this after installing all the packages to usb that I want. if [ -d /usb/etc/ ]; then ln -s /usb/etc/* /etc/ fi if [ -d /usb/usr/sbin/ ]; then ln -s /usb/usr/sbin/* /usr/sbin/ fi if [ -d /usb/usr/share/ ]; then ln -s /usb/usr/share/* /usr/share/ fi if [ -d /usb/usr/lib/ ]; then ln -s /usb/usr/lib/*.* /usr/lib/ fi if [ -d /usb/usr/include/ ]; then mkdir /usr/include ln -s /usb/usr/include/* /usr/include/ fi[/CODE] Quote Link to comment Share on other sites More sharing options...
digininja Posted November 8, 2012 Share Posted November 8, 2012 On my way to be last night I realised that I had answered the question and not the problem and that an init script would be much better, then I saw your mail and figured there was no point logging back on as you'd already come up with the idea yourself. Quote Link to comment Share on other sites More sharing options...
Whistle Master Posted November 8, 2012 Share Posted November 8, 2012 Give also a try to my module called logcheck, you will be able to either monitor your log or put your own script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.