Activate command when computer is idle


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Activate command when computer is idle
# 1  
Old 09-22-2018
Activate command when computer is idle

I would like to run a command if my computer is idle.

I found this, but is not quite working.

Code:
#!/bin/sh
idletime=$(xprintidle)
threshold=300000 # 5 min = 5 * 60 * 1000 ms
if [ "$idletime" -gt "$threshold" ]; then
  echo "idle for 5 minutes."
fi


Last edited by Scott; 09-22-2018 at 04:53 PM.. Reason: Code tags
# 2  
Old 09-22-2018
Hi,

I think there are two main questions here: firstly, when you say that it "is not quite working", what is going wrong ? Are you getting an error, or do you find that the idle message is never displayed ? If you can give some detail on what precisely is gong wrong and how you're determining that it's gone wrong, that will be helpful.

Secondly: what is it you're intending to do once the idle threshold is reached ? I ask because it may well be that other utilities already exist to detect and perform your idle task without you having to re-invent the wheel. For example, if you simply wish to lock your X session, then things like xscreensaver or xlock (or its various successors) may well do the job without you having to worry any more about it. So if you can explain why you need to detect the system being idle and what you plan on doing when it is, there may be other solutions here aside from writing something yourself.
# 3  
Old 09-22-2018
For example, I would like to terminate Seamonkey if there has been no mouse or keyboard input.

The script never executes the echo statement.
# 4  
Old 09-22-2018
Quote:
Originally Posted by drew77
For example, I would like to terminate Seamonkey if there has been no mouse or keyboard input.

The script never executes the echo statement.
If you aren't typing the command to invoke your script (thereby providing keyboard input), how are you invoking your script?

If you have it set up as a cron job, is xprintidle on your system's default search path? And, if so, there is no terminal associated with a cron job. Did you check your mailbox for output produced by your cron job?
# 5  
Old 09-22-2018
Yes, I was invoking script by typing it.

Using a cron job involves a complexity that I would like to avoid.

You have brought up some good points and I need to do some more thinking. :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Idle command to kill the process running n unx box machine

Hi Team , I have one process named as cec_analysiseool that is running on unix box machine now i want to kill this process so please advise what will be the ideal command to kill this , what i have tried is :confused: kill -9 `ps -ef | grep cec_analysiseool | grep -v grep | awk '{print $2}'` (2 Replies)
Discussion started by: unclesamm
2 Replies

2. Shell Programming and Scripting

How to get the information about cpu idle from top command?

I am using Ubuntu 9.04. I want to write a shell script to get the information about cpu idle from top command at the real time when i call it, compare cpu idle with 20 (20%), if cpu idle > 20 exit 1, vice versa exit 0. Anybody can help me to resolve it ? Thanks alot. (7 Replies)
Discussion started by: huyquocnguyen
7 Replies

3. Shell Programming and Scripting

How to run a process when the computer is idle?

Hi there, I wrote a script that scans a folder for new files. I don't want to run it at specific times but only when the computer is NOT busy. I tried to use nice but it doesn't really work. I mean, even if my process has less priority, it still slows down the other processes. I did a test... (3 Replies)
Discussion started by: chebarbudo
3 Replies

4. Solaris

Solaris user account de-activated, command to activate again

My admin has set password policy to de-activate user account if there is not login for 90 days. How can i re-activate user account w/o deleting, or changing user password. Thanks in advance Deeps (6 Replies)
Discussion started by: admin@solaris
6 Replies

5. Red Hat

activate ftp from xinetd

Hello all, I´m trying to configure the ftp service (port 21) in a Red Hat Enterprise 4 from xinetd. Anybody have done this? Thank you in advance. (3 Replies)
Discussion started by: mig28mx
3 Replies

6. IP Networking

How to activate a network interface?

What are the steps between "ifconfig eth0 UP" and "net_device->open"? ifconfig eth0 UP => ioctl(skfd, SIOCSIFFLAGS, &ifr) (ifr.ifr_flags = IFF_UP | IFF_RUNNING) => ????? => what are these steps? net_device->open Thanks! (1 Reply)
Discussion started by: samuncle
1 Replies

7. UNIX for Advanced & Expert Users

activate and deactivate

hi all by using gethostbyname, i can know whether the net is available or not. it is working fine when i activate or deactivate in neat. the problem is when i remove cable(netcable) it is not working proparly, i would like to know it. am using fedora5, AMD can u please help me . thank... (3 Replies)
Discussion started by: munna_dude
3 Replies

8. UNIX for Dummies Questions & Answers

How to run a script when your computer is idle

I am trying to run a script that I made when my computer is idle. How do I go about doing this. Thanks :) (4 Replies)
Discussion started by: rehansaeed
4 Replies

9. UNIX for Dummies Questions & Answers

how do i activate php on linux....

i have activated mysql, and apache on my redhat 9 box, i went to mr BASH and wrote a php script, and it wouldn't execute. any help????????????????????????????????????? is there something that i need to activate??????? i have RUBY on there too,does it matter or no??? ... (2 Replies)
Discussion started by: mbabeli
2 Replies

10. Slackware

how to activate USB mouse

:confused: I am using Linux for a while and now changed to slackware for my study and it is not as good as redhat everytime when you add this or that it needs either configure modules or recompile kernel Now I changed from PS/2 mouse to USB trouble starts it refuse to work I know I can... (3 Replies)
Discussion started by: slackware
3 Replies
Login or Register to Ask a Question