LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-21-2015, 10:00 PM   #1
luofeiyu
Member
 
Registered: Aug 2015
Posts: 237

Rep: Reputation: Disabled
Why the shell can't be exectuted ?


I edit the file as /home/keep_eye.sh.
Code:
sleep 3600
sync
echo -n "if you want to close computer ,please input y"
read closeit
if [ $closeit = 'y']
then
    shutdown -h now
else
    echo "continue"
fi
The computer will be shutdown every 60 miniutes at my willing.
The shell was crontabed with command
Code:
    crontab -e 
    @reboot  sh /home/keep_eye.sh
It will not be executed ,why ?

Last edited by luofeiyu; 12-21-2015 at 10:49 PM.
 
Old 12-21-2015, 10:55 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
When running from crontab, the standard input of the script is directed to /dev/null, so 'read' will never get 'y' from there.
 
Old 12-21-2015, 11:03 PM   #3
luofeiyu
Member
 
Registered: Aug 2015
Posts: 237

Original Poster
Rep: Reputation: Disabled
The three lines code here
Code:
sleep 3600
sync
shutdown -h now
can protect my eye for every hour to shutdown my pc when to set in crontab,but sometimes i have an important work to do ,i have to work continuously.
How to solve the problem then?
 
Old 12-22-2015, 07:05 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Unclear, you claim that you wish to force a shutdown once per hour to alleviate eyestrain. Therefore why allow an option to cancel it? However I do understand that people ultimately will wish to have that option.

Run the cron job to shutdown once per hour, but how about sleep for 3300 and then use wall(1) to send a message to all terminals stating that the system will be shut down in 5 minutes and alert them to cancel, or restart the cron job if they wish to delay the process. Then sleep another 300 and finally shutdown if the cron wasn't restarted.
 
Old 12-22-2015, 10:06 AM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Wouldn't a "typing break" applet accomplish the same thing? Many Linux distros include one by default, or you can do a web search for "linux typing break" (without the quotes) for some alternatives.
 
Old 12-24-2015, 08:02 AM   #6
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Rep: Reputation: 111Reputation: 111
another approach is, instead of it reading from terminal (which is not available in the cron), let it check for the existence of a certain file in, say, /tmp.
It's not safe at all; but then again... there are flaws already pointed out.

Code:
sleep 3600
sync
if [[ ! -e /tmp/noshutdown ]]
then
    wall "Shutting down in a few seconds, please save your work."
    shutdown -h 10
else
    wall "Not shutting down, the file /tmp/noshutdown exists."
fi
Myself, I would find such a script highly annoying... but that's me I suppose.
You could also, instead of shutting down the system, force the screen to turn off / on, when using X:

to turn it off:
Code:
xset dpms force off
 
Old 01-04-2016, 02:33 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
get a raspberry pi and use the GPIO pins to periodically switch a relay which
pumps 240v AC into your keyboard, forcing you to stop/die.
 
  


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
LXer: Shell Scripting Part 3: Decision Control Structures in Shell Scripts LXer Syndicated Linux News 0 05-05-2015 10:01 PM
LXer: Shell Scripting Part 2: Accepting Inputs and Performing Shell Arithmetic LXer Syndicated Linux News 0 04-30-2015 07:10 AM
win32,shell code,shell programming,shell scripting? mr.cracker Linux - Newbie 4 07-12-2013 11:20 PM
[SOLVED] Needed to be $HOME/.bashrc disabled when user shell is 'rbash' (restricted shell) mgumbau Linux - General 2 06-16-2011 06:17 AM
LXer: Shell tip: Set the shell prompt and themes in Linux Terminal LXer Syndicated Linux News 0 06-12-2007 03:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:35 PM.

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