Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Mon, May 24, 2010 at 11:43 AM, Arun Khan knu...@gmail.com wrote: 'at' is a one time deal. It is fine if you want your machine to shutdown at a specific time. I also use it to _start_ the download of iso or big package files after midnight but what about shutting down the machine after the download is complete? It is not deterministic therefore you need to monitor the no. of TCP connections on your system at regular intervals. IMO, cron is the best option. Oops. This thread is getting a bit tedious. Let us move on. The idea is never to cron this reboot business. I run the script I sent only when I feel like it. Not always. So it is one shot like at(1). So at(1) is a good tool to use for this purpose too. -Girish -- Gayatri Hitech web: http://gayatri-hitech.com SpamCheetah Spam filter: http://spam-cheetah.com ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Mon, 2010-05-24 at 11:43 +0530, Arun Khan wrote: On Sat, May 22, 2010 at 11:31 PM, Raja Subramanian rajasuper...@gmail.com wrote: On Wed, May 12, 2010 at 8:43 PM, Arun Khan knu...@gmail.com wrote: I do something similar for overnight downloads on my netbook. The system shuts down when there is 0 TCP connection. I just use at, but I should look into something more sophisticated. My typical at usage: liraz:~# at now + 5 hours warning: commands will be executed using /bin/sh at /sbin/poweroff at EOT job 12 at Sun May 23 04:24:00 2010 I was about to respond if it is just turning off the system why not use 'shutdown +300' which does the same as above. But thought of checking the diff between shutdown and poweroff. I looks like shutdown does things more gracefully than poweroff. But shutdown does not switch off the machine, if you want shutdown to do so you need to use -P. As per the link below http://www.sunmanagers.org/pipermail/summaries/2001-October/000142.html http://linuxservertutorials.blogspot.com/2009/03/how-to-power-off-ubuntu-server-with.html ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Fri, May 21, 2010 at 9:03 PM, Arun Khan knu...@gmail.com wrote: Remember, poweroff may not work on all architectures. One assumes that the reader can figure out the equivalent tool to replace 'poweroff' in respective architecture. You did not get my point Arun. Sorry. I mean that there should be BIOS driver support in APM/ACPI. -Girish -- Gayatri Hitech web: http://gayatri-hitech.com SpamCheetah Spam filter: http://spam-cheetah.com ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Fri, May 21, 2010 at 3:28 PM, Arun Khan knu...@gmail.com wrote: On Wed, May 19, 2010 at 7:47 PM, Parin Sharma parin.sha...@gmail.com wrote: On Wed, May 12, 2010 at 8:43 PM, Arun Khan knu...@gmail.com wrote: Arun Sir, it would be nice if you can share that script !! I have been searching for such solution for a long time !! Rather than give you the script it would be better if you write (you should be able to do in one or two lines in the script) your own script based on the usage of the following tools: 1. 'netstat -nt' to list all TCP connections without DNS resolution 2. 'egrep' to filter out ESTABLISHED connection lines from above 3. use 'wc -l' to count the number of ESTABLISHED connection lines from above step. and save it in a variable no_conns 4. invoke '/sbin/poweroff' if no. of $no_conns is -eq 0 5. Test the script and when you are satisfied that it works then 6. In /etc/cron.d/ create a file with crontab entries similar to what may already be there in that directory. 7. Edit the min. field for frequency (interval in mins.) and hour field for the time duration during which your script should be executed. Your power off script will run every 'x' min. interval during hours a through b If you are setup is correct (script and cron entries). Caveat: it is assumed you log off from all your ssh/telnet sessions and also remove any browser tab that refreshes it's respective page every so often. -- Arun Khan Thanks Sir !! -- Parin Sharma http://twitter.com/FOSSmaniac ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Wed, May 12, 2010 at 8:43 PM, Arun Khan knu...@gmail.com wrote: I do something similar for overnight downloads on my netbook. The system shuts down when there is 0 TCP connection. I just use at, but I should look into something more sophisticated. My typical at usage: liraz:~# at now + 5 hours warning: commands will be executed using /bin/sh at /sbin/poweroff at EOT job 12 at Sun May 23 04:24:00 2010 - Raja ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Sat, May 22, 2010 at 11:31 PM, Raja Subramanian rajasuper...@gmail.com wrote: On Wed, May 12, 2010 at 8:43 PM, Arun Khan knu...@gmail.com wrote: I do something similar for overnight downloads on my netbook. The system shuts down when there is 0 TCP connection. I just use at, but I should look into something more sophisticated. My typical at usage: liraz:~# at now + 5 hours warning: commands will be executed using /bin/sh at /sbin/poweroff at EOT job 12 at Sun May 23 04:24:00 2010 - Raja I have also used it. Yday I had set at(1) to upload my file after p7zip whch is very slow. Sometimes I don't have the patience of girls to sit and hand hold my computer. I feel like cycling and getting some fresh air. Yday I had done this and I kept checking my VPS. How can she disobey my order? I came all the way from my office to find that the power had gone off. ;) Raja clearly demonstrated the best way at should be used. You enter commands directly into the at STDIN and press EOF Ctrl-D. You can instead issue a shell script file as well. But remember this will not work like cron. atd has to be running. Don't get fooled into thinking that at will give some future benefit until you test it with simple print commands or music playing commands. I love the flexibility of timespecs you can give to at. -Girish -- Gayatri Hitech web: http://gayatri-hitech.com SpamCheetah Spam filter: http://spam-cheetah.com ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
Good Script idea - Arun Khan On Fri, May 21, 2010 at 3:28 PM, Arun Khan knu...@gmail.com wrote: On Wed, May 19, 2010 at 7:47 PM, Parin Sharma parin.sha...@gmail.com wrote: On Wed, May 12, 2010 at 8:43 PM, Arun Khan knu...@gmail.com wrote: Arun Sir, it would be nice if you can share that script !! I have been searching for such solution for a long time !! Rather than give you the script it would be better if you write (you should be able to do in one or two lines in the script) your own script based on the usage of the following tools: 1. 'netstat -nt' to list all TCP connections without DNS resolution 2. 'egrep' to filter out ESTABLISHED connection lines from above 3. use 'wc -l' to count the number of ESTABLISHED connection lines from above step. and save it in a variable no_conns 4. invoke '/sbin/poweroff' if no. of $no_conns is -eq 0 5. Test the script and when you are satisfied that it works then 6. In /etc/cron.d/ create a file with crontab entries similar to what may already be there in that directory. 7. Edit the min. field for frequency (interval in mins.) and hour field for the time duration during which your script should be executed. Your power off script will run every 'x' min. interval during hours a through b If you are setup is correct (script and cron entries). Caveat: it is assumed you log off from all your ssh/telnet sessions and also remove any browser tab that refreshes it's respective page every so often. -- Arun Khan ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc -- From, B.Sivakumar (¨`·.·´¨) Always `·.¸(¨`·.·´¨) Keep Smiling (¨`·.·´¨)¸.·´ N Be Happy!! `·.¸.·´ ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
This looks pretty comprehensive to me. Good idea. Remember, poweroff may not work on all architectures. -Girish On Fri, May 21, 2010 at 3:28 PM, Arun Khan knu...@gmail.com wrote: On Wed, May 19, 2010 at 7:47 PM, Parin Sharma parin.sha...@gmail.com wrote: On Wed, May 12, 2010 at 8:43 PM, Arun Khan knu...@gmail.com wrote: Arun Sir, it would be nice if you can share that script !! I have been searching for such solution for a long time !! Rather than give you the script it would be better if you write (you should be able to do in one or two lines in the script) your own script based on the usage of the following tools: 1. 'netstat -nt' to list all TCP connections without DNS resolution 2. 'egrep' to filter out ESTABLISHED connection lines from above 3. use 'wc -l' to count the number of ESTABLISHED connection lines from above step. and save it in a variable no_conns 4. invoke '/sbin/poweroff' if no. of $no_conns is -eq 0 5. Test the script and when you are satisfied that it works then 6. In /etc/cron.d/ create a file with crontab entries similar to what may already be there in that directory. 7. Edit the min. field for frequency (interval in mins.) and hour field for the time duration during which your script should be executed. Your power off script will run every 'x' min. interval during hours a through b If you are setup is correct (script and cron entries). Caveat: it is assumed you log off from all your ssh/telnet sessions and also remove any browser tab that refreshes it's respective page every so often. -- Arun Khan ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc -- Gayatri Hitech web: http://gayatri-hitech.com SpamCheetah Spam filter: http://spam-cheetah.com ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Fri, May 21, 2010 at 5:41 PM, Girish Venkatachalam girishvenkatacha...@gmail.com wrote: This looks pretty comprehensive to me. Good idea. That is power of Unix/Linux/*BSD - you have the utilities; apply your mind to build your own toolset :) Remember, poweroff may not work on all architectures. One assumes that the reader can figure out the equivalent tool to replace 'poweroff' in respective architecture. -- Arun Khan ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Wed, May 12, 2010 at 8:43 PM, Arun Khan knu...@gmail.com wrote: On Wed, May 12, 2010 at 1:47 PM, Shakthi Kannan shakthim...@gmail.com wrote: pgrep mplayer || shutdown -hP now I do something similar for overnight downloads on my netbook. The system shuts down when there is 0 TCP connection. -- Arun Khan Arun Sir, it would be nice if you can share that script !! I have been searching for such solution for a long time !! -- Parin Sharma http://twitter.com/FOSSmaniac ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
[Ilugc] My deceptively simple shutdown script after music playsq
Hello everyone, Here is a very simple recipe for a common need. I have been wanting to automatically switch off my machine after the music stops playing. This could be at night or during daytime when you lock your house and leave. This simple shell script does a great job when run as root. But remember that you should be able to switch off the machine in software. APM support has to work. Nowadays it is no issue. Here is the silly program that does the job. [-] #!/bin/sh while [ 1 = 1 ]; then do sleep 15 echo Checking for mplayer... stat=`pgrep mplayer` if [ $stat = ]; then shutdown -hP now fi done [-] Since I only play music using mplayer this works for me. You need to choose some other audio/video player in case you are not like me. Hope it is useful in some strange way. Thanks. -Girish -- Gayatri Hitech web: http://gayatri-hitech.com SpamCheetah Spam filter: http://spam-cheetah.com ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
what if you had stopped it for doing something On Wed, May 12, 2010 at 1:02 PM, Girish Venkatachalam girishvenkatacha...@gmail.com wrote: Hello everyone, Here is a very simple recipe for a common need. I have been wanting to automatically switch off my machine after the music stops playing. This could be at night or during daytime when you lock your house and leave. This simple shell script does a great job when run as root. But remember that you should be able to switch off the machine in software. APM support has to work. Nowadays it is no issue. Here is the silly program that does the job. [-] #!/bin/sh while [ 1 = 1 ]; then do sleep 15 echo Checking for mplayer... stat=`pgrep mplayer` if [ $stat = ]; then shutdown -hP now fi done [-] Since I only play music using mplayer this works for me. You need to choose some other audio/video player in case you are not like me. Hope it is useful in some strange way. Thanks. -Girish -- Gayatri Hitech web: http://gayatri-hitech.com SpamCheetah Spam filter: http://spam-cheetah.com ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc -- with love from India, swamy , wattabottles http://meswamy.blogspot.com ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
[-] #!/bin/sh while [ 1 = 1 ]; then do sleep 15 echo Checking for mplayer... stat=`pgrep mplayer` if [ $stat = ]; then shutdown -hP now fi done [-] Above script looks good, but I like to propose my modifications in that. #!/bin/sh echo Checking for mplayer... stat=`pgrep mplayer` if [ $stat = ]; then shutdown -hP now fi Love to save the above script as the watchdog.sh. Instead of going for a infinite loop with sleep command, I would add script along with watch as $watch ./watchdog.sh -- Ravi Jaya Mobile: +91 97909 16181 ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
Hi, --- On Wed, May 12, 2010 at 1:02 PM, Girish Venkatachalam girishvenkatacha...@gmail.com wrote: | I have been wanting to automatically switch off my machine after the | music stops playing. | | This simple shell script does a great job when run as root. | | #!/bin/sh | | while [ 1 = 1 ]; then | do | sleep 15 | echo Checking for mplayer... | stat=`pgrep mplayer` | if [ $stat = ]; then | shutdown -hP now | fi | done \-- Try the following in the command section of an /etc/crontab entry? pgrep mplayer || shutdown -hP now SK -- Shakthi Kannan http://www.shakthimaan.com ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Wed, May 12, 2010 at 1:47 PM, Shakthi Kannan \-- Try the following in the command section of an /etc/crontab entry? pgrep mplayer || shutdown -hP now Shakthi, I think this a lot. I normally use like $ make make test make install Of course for make install you gotta be root if it uses the normal prefix during ./configure. I digress. Sorry. The or operator || is really cool. But I would not put it in crontab. If the machine switches off doing imp work and listening to music there is a problem. I want to run the script manually. Thanks for this tip. Very useful. -Girish -- Gayatri Hitech web: http://gayatri-hitech.com SpamCheetah Spam filter: http://spam-cheetah.com ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Wed, May 12, 2010 at 1:37 PM, Ravi Jaya Above script looks good, but I like to propose my modifications in that. #!/bin/sh echo Checking for mplayer... stat=`pgrep mplayer` if [ $stat = ]; then shutdown -hP now fi Love to save the above script as the watchdog.sh. Instead of going for a infinite loop with sleep command, I would add script along with watch as $watch ./watchdog.sh Ravi, I have not used watchdog or watch anytime. Thanks. That should also work. Ah I later realized that you are talking about the watch command which I learnt recently. That is nice too. You are just calling the script watchdog.;) Okay. -Girish -- Gayatri Hitech web: http://gayatri-hitech.com SpamCheetah Spam filter: http://spam-cheetah.com ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Wed, May 12, 2010 at 1:26 PM, swamynathan mesw...@gmail.com wrote: what if you had stopped it for doing something Well then mplayer would still return as running for pgrep. And not shut down since the condition would not be met. -Girish ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Re: [Ilugc] My deceptively simple shutdown script after music playsq
On Wed, May 12, 2010 at 1:47 PM, Shakthi Kannan shakthim...@gmail.com wrote: pgrep mplayer || shutdown -hP now I do something similar for overnight downloads on my netbook. The system shuts down when there is 0 TCP connection. -- Arun Khan ___ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc