Jump to content

Cron and SSMTP script


Razzlerock

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :-)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

As I expected, the fix was right under my nose :wacko:

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.

Link to comment
Share on other sites

As I expected, the fix was right under my nose :wacko:

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...