LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-23-2015, 09:28 AM   #1
Aashika
LQ Newbie
 
Registered: Sep 2014
Posts: 15

Rep: Reputation: Disabled
mail everyday without cron


hello,
I have to mail the status of my server everyday.
How do I write a script which will help me do so??
I DO NOT want to use cron job. Is there some other alternative using which I can accomplish my task.

Thankyou
 
Old 04-23-2015, 09:37 AM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
You can use a shell script along with a MTA to send. Script can be started manually or while system boots up with init scripts.
 
Old 04-23-2015, 09:42 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Aashika View Post
hello,
I have to mail the status of my server everyday. How do I write a script which will help me do so??
There are THOUSANDS of easily-found scripting tutorials. Please see the "Question Guidelines" link in my posting signature. We'll be happy to help you, so post what you've written/tried, and tell us where you're stuck. Otherwise, see the scripting tutorials to help get you started.
Quote:
I DO NOT want to use cron job. Is there some other alternative using which I can accomplish my task.
WHY don't you want to use cron to run a script once a day?? That's exactly what it's for...cron is only a job scheduler. If you don't want to use it, you can use "at" to run a job, and have your script schedule a new one every single day (VERY inefficient, but doable), or you could just put a sleep statement for 86400 seconds to run every 24 hours (again, doable but not good).
 
Old 04-23-2015, 09:43 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by veerain View Post
You can use a shell script along with a MTA to send. Script can be started manually or while system boots up with init scripts.
The OP stated they need the script every day...so running it once at boot time or manually won't do it.
 
Old 04-23-2015, 09:57 AM   #5
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by TB0ne View Post
The OP stated they need the script every day...so running it once at boot time or manually won't do it.
So how come cron runs all the time. Can't a scipt be made which keeps on running like cron or a daemon.
 
Old 04-23-2015, 09:58 AM   #6
Aashika
LQ Newbie
 
Registered: Sep 2014
Posts: 15

Original Poster
Rep: Reputation: Disabled
THANKYOU..
'at' command was exactly what I was looking for.
 
Old 04-23-2015, 12:13 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by veerain View Post
So how come cron runs all the time. Can't a scipt be made which keeps on running like cron or a daemon.
Cron runs, because IT WAS DESIGNED TO...it's a daemon which runs other jobs. That's what it does. Yes, you CAN write a script to do it, or a daemon which duplicates functions of cron, but why bother?? That's why cron was written all those years ago, and is still used.

You wrote that they should have it run at boot time, or they could run it manually. Neither of which answers the OP's question about having it run every day.

---------- Post added 04-23-15 at 12:14 PM ----------

Quote:
Originally Posted by Aashika View Post
THANKYOU..
'at' command was exactly what I was looking for.
Great..but you still haven't said why cron won't work, since it is MUCH better suited to what you're doing. Having a script to re-schedule an at job every day is MUCH more effort than it's worth, and all you're doing is duplicating what cron already does.
 
1 members found this post helpful.
Old 04-23-2015, 02:26 PM   #8
yo8rxp
Member
 
Registered: Jul 2009
Location: Romania
Distribution: Ubuntu 10.04 Gnome 2
Posts: 102

Rep: Reputation: 31
run a script in the background called from /etc/rc.local or watever runlevel S99 blah blah you want

#!/bin/bash

while true
do
sleep 3600 # time in seconds
# here echo whatever info you want into body.mail file # first line is Subject:whatever , below is the content
/usr/sbin/sendmail -v mail@domain.com < body.mail
done
 
Old 04-24-2015, 12:40 AM   #9
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by TB0ne View Post
Cron runs, because IT WAS DESIGNED TO...it's a daemon which runs other jobs. That's what it does. Yes, you CAN write a script to do it, or a daemon which duplicates functions of cron, but why bother?? That's why cron was written all those years ago, and is still used.
Oh I know cron is just for that task. But OP asked specifically he doesn't wants to use cron. Then only I suggested to make a script.
 
Old 04-24-2015, 08:10 AM   #10
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by veerain View Post
Oh I know cron is just for that task. But OP asked specifically he doesn't wants to use cron. Then only I suggested to make a script.
Right...which they already said they were going to write anyway, and they needed it to run daily. they were then asked why they couldn't use cron (and they still haven't responded). you can write a script/program to do anything, but re-writing something to duplicate what already exists is pointless. telling the op to run it at boot time will only run it once a day if they reboot every day. running it manually will only solve their problem if they remember to run it every day.
 
Old 04-25-2015, 01:35 AM   #11
Aashika
LQ Newbie
 
Registered: Sep 2014
Posts: 15

Original Poster
Rep: Reputation: Disabled
Sorry for replying so late.
We are not using cron because, if anything is to be scheduled then cron is the best option and anyone can edit or delete cron easily.
Hence, we wanted an alternative for cron, which is to write a script which couldn't be that easily tampered with.
 
Old 04-26-2015, 11:46 AM   #12
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by Aashika View Post
Sorry for replying so late.
We are not using cron because, if anything is to be scheduled then cron is the best option and anyone can edit or delete cron easily.
Hence, we wanted an alternative for cron, which is to write a script which couldn't be that easily tampered with.
Using cron is the more robust solution. If your script aborts abnormally for whatever reason your job is dead.
The risk of this happening is a lot lower with cron.
If you don't want normal users to be able to "tamper" with it, put the job into root's crontab.
 
Old 04-26-2015, 11:00 PM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Aashika View Post
Sorry for replying so late.
We are not using cron because, if anything is to be scheduled then cron is the best option and anyone can edit or delete cron easily. Hence, we wanted an alternative for cron, which is to write a script which couldn't be that easily tampered with.
Wrong...only root can edit roots cmon, and each user can have their own that only they can edit. And an at job can also easily be deleted, and shell scripts can be killed. Your logic is flawed.

The script that is run by cron is no more (or less) vulnerable than if you run it manually, or through an at job. All cron does is execute the script, that's all. If someone is root, they can do anything they want...so, protect your script through correct user permissions, and don't give people root access unless they need it.

Last edited by TB0ne; 04-27-2015 at 08:01 AM.
 
Old 04-27-2015, 07:18 PM   #14
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
whether you use crontab or at, both get handled by the crond service...

http://www.ibm.com/developerworks/li...ob-scheduling/
 
1 members found this post helpful.
Old 04-28-2015, 04:09 PM   #15
mattydee
Member
 
Registered: Dec 2006
Location: Vancouver, BC
Distribution: Debian,Ubuntu,Slackware
Posts: 479

Rep: Reputation: 48
What a bizarre request. "I want to something to control my car but I refuse to use the steering wheel."
 
  


Reply



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
How do I create a cron job that will run everyday at 12:20am? and 5:20 AM ? wireshark11 Linux - Newbie 8 01-29-2014 08:08 PM
How can I write a script to send general mail to my users at 9AM everyday in Linux 4 mostafaashish Linux - General 3 03-03-2010 06:19 AM
Cron mail sending using outside SMTP mail server Utah Linux - Software 6 08-24-2005 07:44 PM
No More Cron Mail, Cron Error? Xhost Linux - General 3 07-26-2004 04:28 PM
need only cron job mail on my mail id manojthakkar Linux - Newbie 0 12-20-2003 05:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:02 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration