Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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).
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
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.
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
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.