I m using putty on windows server to login into remote server. I need to monitor some jobs on that remote linux box. I need some script or binary file, that will send me notification on windows server/pc as soon as job fails on remote server.
Notify-send is not working there. I m using redhat linux.
You can set a cron job in your Linux machine, which will will mail you if any failure occurs or any detail you needed. Example, I am using this service to monitor dump copy process.
This script will take backup and after completion notify me on my mail.
#!/bin/bash
date=`date -d '1 hour ago' "+%Y-%m-%d-%H"`
#/usr/bin/svnadmin dump /abc/xyz/ > /home/server1/backup/dump_$date.dump
/usr/bin/svnadmin dump /abc/xyz/ > /root/svn/dump_$date.dump
mail -s "SVN DUMP" abc#xyz.com < /opt/body.txt
Here, the body.txt file will contain the mail body.
cron will execute this file as below:
1 1 * * * sh dump.sh
This may help.
Related
I am trying crontab but crontab for email is not working.However, I want that crontab runs a shell script and that shell script runs a python script.
One crontab I tried is
* * * * * echo " This is current date and time $(date)"
but this is not getting printed on screen. I don't understand what is wrong I am doing.
for sending the email form this command.
echo " This is a message " | mailx -s "Subject" mymail#email.com
you need to make sure port 25 is open on your system.
you can use the mailq command for check email in the queue on your system.
you can check local port is open or not from
telnet localhost 25
nc localhost 25
Can anyone please let me know if there are any ways that we can monitor a directory in centOS (linux) which is present in different server and when a new file arrives in that directory I need to copy that file to my server.
One way would be to have rync command running periodically on cron job. rysnc is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending
only the differences between the source files and the existing files in
the destination.
If you want to run transfer from remote server to local server like every 10 minutes you add a line like below in your crontab. It also does few other things:
Zip the files
Transfer over ssh
Logs output
Note: You will have to do ssh key exchange to avoid the password prompt.
*/10 * * * * /usr/bin/rsync -zrvh -e ssh root#<remoteIP>:<remoteDir> >/var/log/rsync_my.log 2>&1
I have a GMail account that is set to only receive an email with a certain subject.
I need some linux commands to trigger when it finds unread versions of this email.
The commands are just application calls so I could record my desktop while it runs.
xrandr --size 1360x768
timeout 2h recordmydesktop
xrandr --size 1366x768
I already created a filter on gmail for the email itself, but now I have no idea what to do next. I was told to set up fetchmail that would fetch unread emails in the folder I set-up.(and mark the newly fetched email as read on gmail so it wouldn't read the same mail over and over). This is the script I got, but i'm not sure if ths script does what I need it to.
poll imap.gmail.com protocol IMAP
user "l**********#gmail.com"
password '*****'
folder 'Pic*******'
fetchmail -c
keep
ssl
Next is that I was told to set up a procmail script to trigger my linux commands whenever fetchmail says that it found an unread version of the email. but I'm not exactly sure how to do it. I also need to set up cronjob to have this script trigger every few minutes.
fetchmail is good at downloading messages. procmail is good at filtering messages and executing arbitrary linux commands based on the mail received.
To set up fetchmail to run every 10 minutes as a cronjob and pass the mail it receives to procmail, run crontab -e and add the following line:
*/10 * * * * /usr/bin/fetchmail -N -d0 -f $HOME/.fetchmailrc -m "/usr/bin/procmail $HOME/.procmailrc"
You will need to create a ~/.procmailrc file to do the filtering and executing.
You have not said what commands you want to run. As an example, just for the purpose of giving you ideas, the following stanza from a ~/.procmailrc file selects messages from somebody#example.com with the subject heading New File. The body of the message is then uudecoded and the output from the uudecoder is then untarred:
:0 w
* ^From:.*somebody#example.com
* ^Subject: New File
| uudecode -o /dev/stdout | tar -xzC /var/tmp/
The requirement to run X commands somewhat complicates matters. Cron is not really suitable -- even if your computer is only turned on when you are logged in, the general X architecture is based on privilege separation -- commands running in your current X session have access to the GUI, others do not.
Running Fetchmail and Procmail from within your X session is kind of awkward as well, but if you have a dedicated email account for this task, I don't suppose you mind accidentally losing an email message occasionally.
Thus, instead of a Cron job, I would suggest a simple background script running from your .xsession or similar.
#!/bin/sh
while true; do
fetchmail -N -d0 -f $HOME/.fetchmailrc -m "/usr/bin/procmail $HOME/.procmailrc"
sleep 600
done
The Procmail recipe could look something like
:0
* ^Subject: whatever
| xrandr --size 1360x768 ;\
timeout 2h recordmydesktop; \
xrandr --size 1366x768
I want to monitor jboss server status in linux for keep up & running the application.My requirement is if server down , i need to get the email from server.
So i'm planning to run crontab in linux for every hour or half an hour to check the server status.
30 * * * * ps -ef|grep java | mail test#domain.com
I' will get grep command result when running above command. So How to read the grep command result to find server is up & running ?
Please advise if anybody have alternative.
In your crontab file write this:
MAILTO="test#domain.com"
30 * * * * pgrep -lf java
At the beginning of cron add
MAILTO="test#domain.com"
This would send the output of commands in cron. You dont require to pipe the output to mail again. (reference)
I'm trying to have root run a script sitting inside another user's bin folder (say 'john'). The script itself is owned by root and chmoded 774.
I can launch the script without any issue from the command line.
Via cron, it does not get started. I can't understand why.
Here is the content if i crontab -e while logged in as root.
# daily backup
15 2 * * * php -q /home/john/bin/backup
My server is a Red Hat Enterprise Linux Server release 6.5 (Santiago)
Perhaps php is not in the default PATH, such as in /usr/local/bin rather than /usr/bin or /bin.
Always redirect the output of both stdout and stderr, otherwise the default has traditionally been to send a message via /usr/bin/mail, and you probably don't want to get an email each time the job runs.
When you revise your crontab (i.e. "/usr/local/bin/php -q /home/john/bin/backup > /tmp/crontest.txt 2>&1") you can then see if any error messages are being logged.