You are not logged in.
Pages: 1
Hi all,
following my other topic to remove the shutdown/reboot/logout power, I now need to make a script to execute the given command at specific time.
What I am trying to do (see script below) is to get the time into a variable, then check if the time is more than the time given or not, I start working on script but the result failed.
#!/bin/bash
time=`date +%k%M` ;
if [ "1830"<"$time" ]
then
gsettings set org.gnome.desktop.lockdown disable-log-out true
elif [ "2220">"$time" ]
then
gsettings set org.gnome.desktop.lockdown disable-log-out fasle
fi
So basically the script will disable the shutdown/reboot/logout user power if after 1830 and re-enable it after 2220, obviously I will make it a loop after that - might be good to get to a point where the script check if the time is between 2220 and 1830 to enable it, or if it's between 1830 to 2220 to disable it.
Many thanks for your time and future assistance,
Regards,
Offline
Maybe you can set up two cronjobs - one at 1830, the other at 2220.
Offline
Well the issue with that is the user doesn't log at specific time, therefore the cron job could have been passed already - other option would be to set the cron job every 10/15 minutes to run that command between those time.
Not ideal I guess,
Offline
There's e.g. http://xyne.archlinux.ca/projects/cronwhip/ - maybe it could help: if the user is logged on at 18.30, run the job; if the user is not logged in, run as soon as he logs in. Ideally don't run it after 22.20 but if the user logs off at 18.00 and logs in at 23.00 both jobs would be run - is it still OK?
Offline
Hi all,
following my other topic to remove the shutdown/reboot/logout power, I now need to make a script to execute the given command at specific time.
What I am trying to do (see script below) is to get the time into a variable, then check if the time is more than the time given or not, I start working on script but the result failed.
#!/bin/bash time=`date +%k%M` ; if [ "1830"<"$time" ] then gsettings set org.gnome.desktop.lockdown disable-log-out true elif [ "2220">"$time" ] then gsettings set org.gnome.desktop.lockdown disable-log-out fasle fi
So basically the script will disable the shutdown/reboot/logout user power if after 1830 and re-enable it after 2220, obviously I will make it a loop after that - might be good to get to a point where the script check if the time is between 2220 and 1830 to enable it, or if it's between 1830 to 2220 to disable it.
Many thanks for your time and future assistance,
Regards,
The '<' and '>' operators inside [ ] are lexcographical, not arithmetic. 830 will be greater than 1030. Since you've specified #!/bin/bash, please use Bash's (( )) syntax, where '<' and '>' will actually perform numerical comparisons.
http://mywiki.wooledge.org/BashGuide/Te … nditionals
Last edited by falconindy (2011-06-03 19:12:41)
Offline
#!/bin/bash
user=someuser
time=$(date +%k%M)
if [[ "$time" -ge 1830 ]] && [[ "$time" -le 2220 ]];then
su -c "gsettings set org.gnome.desktop.lockdown disable-log-out true" $user
else
su -c "gsettings set org.gnome.desktop.lockdown disable-log-out false" $user
fi
Try this. I don't know if gnome settings have to be set as a specific user so i added su.
no place like /home
github
Offline
Great! many thanks,
I have changed the script because it doesn't need "su" and also because I will start the script automatically when the user log in. However, I am trying to make a loop so the script check the time and act accordingly due to the time but it doesn't seems to work (because when the time is up, the option to log out/reboot/power off doesn't return automatically)
#!/bin/bash
time=$(date +%k%M)
while true; do
if [[ "$time" -ge 1830 ]] && [[ "$time" -le 2220 ]];then
gsettings set org.gnome.desktop.lockdown disable-log-out true
else
gsettings set org.gnome.desktop.lockdown disable-log-out false
fi
sleep 300
done
Offline
I think it's better to have cron run the script every ~5 minutes or so.
But if you want the loop inside the bash script you have to evaluate $time from inside the loop. Right now, $time is set only once when the script first starts and will stay that way.
Try this:
#!/bin/bash
time="date +%k%M"
while true; do
if [[ $(eval "$time") -ge 1830 ]] && [[ $(eval "$time") -le 2220 ]];then
gsettings set org.gnome.desktop.lockdown disable-log-out true
else
gsettings set org.gnome.desktop.lockdown disable-log-out false
fi
sleep 300
done
Last edited by demian (2011-06-03 22:15:30)
no place like /home
github
Offline
excellent, seems to work as intended from the testing I have done,
Many thanks for your help!!
Offline
Sorry to dig an old post,
But the script is now returning an error and stop working.
line 4: 040: command not found
Script run at 00:40 any suggestion?
Offline
You must have changed something.
Anyway, rather than sleeping and re-checking all the time, better just check *once* and then use the "at(1)" command
You know you're paranoid when you start thinking random letters while typing a password.
A good post about vim
Python has no multithreading.
Offline
Still don't get it, but now it work.
With the "at" command it will only execute the command at that specific time, but that's not what I want. Anyway thanks for your help
Offline
Pages: 1