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.
Nice to ready your reply, but really it is very hard for me to understand. I am new in linux OS, if you can give me little easy explain, i will be able to find the logic.
I'm not posting this from a linux-machine, so I can't give you all the details you want, but still:
You say, that you have your own shell-script... usually, a shell script starts, does some job and exits. If that's the case, do the following
someone@localhost: $ cd some/dir/where/your/script/is
someone@localhost:/somedir $ ./yourscript &
[ new job id blablabla ]
someone@localhost:/somedir $
Now your script runs in background mode until it finishes. Note: if you close down the console you typed these commands, the script will be terminated too.
If you need further help, it would greatly help if you would as more specifically what you weren't able to do
Hope this helps
p.s. in my previous post, there was a typo: witht the virtual consoles, the key is: ctrl-alt-f1 up to f6. ctrl-alt-f7 is your graphical session (most likely)
Appriciated for your kind of help. here is the Shell Script which i want to run on the background of the system.
==========check.sh=================
#!/bin/sh
while true
do
ps -aux|grep radiusd > live.log
fsize=$(wc live.log | awk '{print $1}')
if [ $fsize = 2 ]; then
echo "Welcome to FooSoft 3.0"
else
#echo "You must be root to run this script"
killall -9 radiusd
/usr/local/sbin/rc.radiusd start > live.log
#echo "Started";
exit 1
fi
sleep 30
done
==================================
If i will run this script, Is it will make more load on the server?
If I guess right, this is a script that checks whether radiusd is running - if not, start it.
If you want to run it by hand, you can copy it to /usr/local/bin, give it exectute permission (chmod +x /usr/local/bin/check.sh) and run it in background: (check.sh &) - then it will run in background mode. since the script never terminates, it kindof runs in background mode.
If you want to have your script run automatically at boot, then you need to check the docs of your distro, since I don't know how your distro manages startup scripts
1) Congratulations on being smart enough to put a sleep in your loop. Many people don't do this and are surpirsed when the CPU gets eaten up. The sleep means your performance shouldn't be dramatically impacted.
2) You should modify the "kill -9" as that should only be done as a last resort because it tells a process to die without cleaning up any resources it is using. Typically you should do a progressive kill: That is do "kill -15" then check to see if PID is gone. If not try "kill -1" then check again and finally do a "kill -9". You should do a final check and have the script exit if the "kill -9" doesn't eliminate the PID (or try it multiple times then exit) as it would indicate you have an issue an you wreak havoc on performance by starting over and over when it won't die.
3) Adding the "&" does indeed background it but you should type "nohup" before the command as well so that it doesn't exit when you logout. Background processes die when the terminal they are associated with is logged out.
4) /usr/local/sbin/rc.radiusd would appear to be your startup script for radiusd itself. You might want to examine it and see if it has a "status" option as many startup scripts do. If so rather than relying on "ps" to determine status you can use the script itself to give this to you.
Hint: when you're using a command, read the manpage to see if you can get just the information you need by option, rather than cutting them out of stdout with filters.
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
About killing gracefully: it is also useful to 'kill -18' process if 'kill -15' doesn't work, and try 'kill -1' only afterwise. If the process is stopped for some reason, though in this particular case it is unlikely, it may not respond even to 'kill -9' until it is continued with 'kill -CONT'.
than you very much for kind of your all helps. now my script is running very well on my need. i wanted to ask one more question how i can check how many deamons are running in my system?
ps -ft? will show you all processes that have no associated terminal. These would be ones that either had been started by some automated item (such as init scripts or cron) or those that had been backgrounded from a terminal which later was logged out.
True daemons will show up in this list but not all that shows up in this list will be daemons. Most daemons process names end in a "d" (e.g. telnetd, ftpd, esd) but not all.
Also note that some daemons ONLY start when required as they are spawned by other daemons. Most of the network stuff (telnetd for example) would only start from inetd or xininetd (depending on your distro and only when there was someone actively telnetted into your server.
Finally note that daemons can be started and backgrounded from a running terminal so would not have ? as the terminal. Additionally there are some that can be started in foreground for debugging purposes so would also not have ? as the terminal (e.g. named).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.