Need to run a script for any user logged in every minute
Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
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.
a) This will start the script for each login. Will the users login twice? Then you would have two or more instances for each user.
b) Will the scripts ever be stopped again? Especially with nohup they will survive the logout AFAIK.
Very true for point (A), although there could be some 'smarts' put into the script to check for a running instance, and not start a second time if so. Wouldn't be too hard to do.
But no, the nohup will just start a second 'shell' in the background. Once the user logs out, it'll also kill that shell too.
Click here to see the post LQ members have rated as the most helpful post in this thread.
The & at the end of the line will fork the process in the background, and will be killed by sighup when the terminal session is closed. By using nohup the signal will be ignored and the script surives.
The & at the end of the line will fork the process in the background, and will be killed by sighup when the terminal session is closed. By using nohup the signal will be ignored and the script surives.
Ahh...I see where you're going.
I assumed the folks would be logging in via console/GUI, and once THAT closes, the session the user started will die. But for a terminal/ssh connection, you're exactly right. Good catch. In that case, OP, you can just omit the "nohup" from the front of the command.
Today is my day off, so I won't be able to test anything till tomorrow. But, for more info and clarification, the users all log into a GUI desktop environment. They open firefox, login to our CRM, and make calls all day. Then they go home. Most of the time they log out, sometimes they forget. So if I called the script from the /etc/profile like so:
Code:
nohup myscript.sh >/dev/null 2>&1&
when they log out, that should kill the process right? Only one person logs into any given computer. In other words, only bob logs into computer A, only sherry logs into computer B...
Okay, then GNUbatch is no option. I thought that all log into one machine via ssh. Nevertheless, on my openSUSE 11.3 with KDE the nohup background process survives when I log out. In this case, I would just put it in ~/.kde4/Autostart to be started w/o nohup or & backgrounding.
Okay, then GNUbatch is no option. I thought that all log into one machine via ssh. Nevertheless, on my openSUSE 11.3 with KDE the nohup background process survives when I log out. In this case, I would just put it in ~/.kde4/Autostart to be started w/o nohup or & backgrounding.
+1
Have to agree with this, given this new info...and providing they use KDE. Although, Gnome has similar options to autostart a process.
I removed calling the script from /etc/profile and moved the script from /usr/local/bin to my users ~/.kde4/Autostart, rebooted, logged in, downloaded a few test .gsm files, ran watch ls -l on my Download directory, and sure enough it runs every minute! Thanks for guiding me through this. It's cool to see what solutions people can come up with. Because we are using ldap, rather than local logons, I then created a script that will allow me to quickly copy the file to everyones (like several hundred users here!) /kde4/Autostart directories:
Code:
#!/bin/bash
UHOME="/home"
FILE="/home/rich.johnson/.kde4/Autostart/convertfromgsm"
USERSUSERS="$(ldapsmb -l -u | cut -d: -f1)"
for u in $USERSUSERS
do
_dir="${UHOME}/${u}/.kde4/Autostart"
if [ -d "$_dir" ]
then
cp "$FILE" "$_dir"
chown $(id -un $u):users "$_dir/convertfromgsm"
fi
done
Lastly, I copied the script the /etc/fstab/.kde4/Autstart directory as well, so that when I create new users in teh future they will have that file. I did have to create the .kde4 and the autostart folder in the skel dir.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.