LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 06-11-2008, 07:51 PM   #1
foramgoram
LQ Newbie
 
Registered: Jun 2008
Posts: 9

Rep: Reputation: 0
Red face Cron job to automatically to runlevel 1 or disconnect al logged on users


Hi All,
I want to write a cron job that will either go to runlevel 1 at specfic time and come back to runlevel 2 after 30 minutes or just disconnect all logged on users at specific time.

Howe could it be done?
I tried to do it with sudo init 1 but the Recovery menu appears, I want that system goes directly to run level 1.

Please help
 
Old 06-12-2008, 05:03 AM   #2
emi_ramo
Member
 
Registered: Apr 2007
Location: Barcelona, Spain
Distribution: Debian, KUbuntu
Posts: 213

Rep: Reputation: 36
First, do crontab for root:

Code:
sudo crontab -e
And then you can try with (I'm not sure at all)

Code:
/etc/init.d/single start
 
Old 06-12-2008, 11:53 AM   #3
foramgoram
LQ Newbie
 
Registered: Jun 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Cool

It takes me to that menu. I want to go straight to bash and run some script with cron in single user mode. But I realize that it is not possible because cron is stopped is single user mode.
Is there any way to disconnect all users automatically at specific time?
 
Old 06-12-2008, 01:01 PM   #4
emi_ramo
Member
 
Registered: Apr 2007
Location: Barcelona, Spain
Distribution: Debian, KUbuntu
Posts: 213

Rep: Reputation: 36
You can go through crontab to single user mode at some time and create some file/mark. Then, into your /etc/rc1.d/ you can add a script to enter again to multiuser mode 30 mins later, may be similar to that:

Code:
#!/bin/bash
SEC=(( 30 * 60 ))
if [ -e /tmp/go_to_multiuser ]; then
   rm /tmp/go_to_multiuser
   sleep $SEC
   init 2
fi
With that you will not execute the script when you boot up your system, only after going to single. Just try and play!
 
Old 06-12-2008, 01:07 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Also, if you look at the init docs you see that it allows for a few more runlevels that are currently used by default. So you could have a custom runlevel 7 that basically runs like "runlevel 1" but in which the only "service" that runs is a script that has a timer, performs what tasks you want and on timer expiry telinits back to runlevel 2. As for the "killuser" part, maybe http://www.linuxquestions.org/questi...36#post3156936.
 
  


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
why runlevel switch message is not logged into /var/log/messages in RHEL5? mnatchad Red Hat 1 05-14-2008 07:11 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
Will my cron job run if i am not logged into the server? mthaha Linux - Desktop 3 10-13-2006 10:17 AM
cron job to execute automatically lifegamer Linux - Newbie 2 09-16-2006 08:35 AM
can't stay logged in at runlevel 5 trb Linux - Software 2 05-25-2005 10:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 09:48 AM.

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