iwel's e-notes about his World
Posts tagged linux
Schedule shutdown
Apr 30th
Commands
at- Execute a task at a specific time. For example, shutdown computer, send birthday remainder etc. Useful to schedule one job at a time or a single future event.
cron – If you want to shutdown Linux box automatically everyday 8 pm then you need to use cron instead of at command (see below for examples). Useful to schedule recurring events or daily events such as backup data, or check system security etc.
at Command Examples
Let us see how to shutdow a Linux automatically at 8 pm, type the command at 8pm and press [enter] key, then type halt followed by enter key. To save your job press CTRL+D.
# at 8pm
Sample outputs:
at> halt
(Press CTRL+D)
Try out the following utilities:
atq – List the current at jobs pending.
atrm – Used to remove pending at jobs.
at command accept fairly complex time specifications, for example:
Run job at 6am on monday:
at 6am monday
Run job in 5 minutes time:
at now + 5 minutes
Run job at 4pm but 3 days later:
at 4pm + 3 days
Run job at 10am on 31st July:
at 10am Jul 31
See the file /usr/share/doc/at/timespec for complete time specifications and read man pages of at, atq, atrm. Make sure you have atd service running, if not start it using the following command:
# /etc/init.d/atd start
I personally wouldn’t schedule a shutdown if i was downloading a few tarballs and the system needed to be off when it was complete, unattended.
what if the speed decreases and it doesn’t finish in time?
Sure, you could expect it to take long and give it lots of time… But what if it gets done early, wouldn’t it be better if it shut down after it was complete, and not wait for the set time?
best to do something like this, chain commands. so you tell it to download the file and then when its done, shutdown.
wget http://somehwere.com/path/to/some.file && halt
note: it has to be double & signs. single one will cause both commands to execute at the same time. double causes it to wait for the first one to exit (clean exit or not) before continuing.
i personally would probably use more along the lines of
wget http://somehwere.com/path/to/some.file 2>/home/kai/wget.log && halt
so level 2 outputs (errors) are logged. if the file stopped downloading before it was done, i would then know why by reading the output of wget.log
scheduled shutdowns with at or cron are better for just having a system shutdown _nomatter what_ at said time. if you want your tasks to finish first, chain them.
Or if you want to schedule a shutdown in the next 24 hours:
shutdown -h time
e.g:
shutdown -h 06:45
Linux find large file size
Jan 14th
Sometimes after using your linux box, data consumes spaces in your hard drive, then you start to think how to find large file size in linux box, after searching a while then i found the solution for this,the following command will list all files in sorted order in human readable format
find /var -size +10000k -print0 | xargs -0 ls -lSh
the explanation for this is : look for files bigger than 10MB in the /var directory, sort it by biggest file first (descending), and show it in human readable format (MegaBytes)
That’s it.. now you can find large file size in your linux box, simple right
Check linux distro version
Jun 17th
having to manage a few server and install services,i need to know what distribution of linux for each box i handle. So, to check linux distro version of my box i would run this in my shell :
cat /proc/version
as for example, the result is like this for ubuntu :
Linux version 2.6.27-14-generic (buildd@palmer) (gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12) ) #1 SMP Wed Apr 15 18:59:16 UTC 2009
as for centos would like this :
Linux version 2.6.18-53.1.14.el5 (mockbuild@builder6.centos.org) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-14)) #1 SMP Wed Mar 5 11:36:49 EST 2008
easy right ?
Change Remote Desktop password from terminal
May 30th
Having installed Remote Desktop on my Ubuntu Intrepid box makes me easy to control my desktop from anywhere to work, but today when i tried to connect to my desktop,i forgot the password for it
then i try to find some answers to change remote desktop password from terminal by googling, so i found this solution for 8.04 :
- gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled false
- gconf-editor
- paste encode password from: http://www.javazoom.net/services/base64/base64.jsp
- or use:
- gconftool-2 -s -t string /desktop/gnome/remote_access/vnc_password <encode_pwd>
- or use:
- System-> preferences-> Remote Desktop
- set pwd as desired…
- manual text edit of %gconf.xml does not seem to work!
- gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled true
- verify .gconf/desktop/gnome/remote_access/%gconf.xml
Permanent Aliases in bash shell
Apr 30th
| Aliases are a convenient feature of shells in Unix-like operating systems that make it possible to launch any command or group of commands (inclusive of any options, arguments and redirection) by merely entering a brief, pre-set string (i.e., sequence of characters).
Although aliases can easily be set up using the alias command, this command has the disadvantage that any alias created with it remains in effect only during the current login session (i.e., until the user logs out or the computer is shut down). This might not be much of a problem for systems that are rebooted (i.e., restarted) only infrequently (such as corporate database servers), but it can be a nuisance for systems that are frequently rebooted (e.g., home computers). Fortunately, however, any alias can be made more enduring (i.e., until it is explicitly removed) by writing it to the appropriate configuration file with a text editor. The name and location of such file can vary according to the system and the shell. In the case of the bash shell (which is the default shell on Linux) on Red Hat Linux, an alias for any user can be added to the .bashrc file in that user’s home directory. Each alias is written in this file exactly the same as it would be written on the command line using the alias command (see The alias Command for examples). Because this configuration file is read at login, any changes to it will not take effect until the user has logged in again or opened a new terminal window (i.e., an all-text window in a GUI). .bashrc is a hidden file, that is, a file whose name begins with a period and thus is not normally visible in a GUI (graphical user interface). However, it is easy to locate and open from the command line. Because .bashrc is a plain_text file, it can easily be edited using any text editor, such as vi or gedit. For example, assuming that the user is currently in its home directory, the following could be used to open .bashrc with vi:
Likewise, the following could be used to open the same file with gedit:
The alias should be typed in below the line that says # User specific aliases and functions. The pound sign at the start of this line indicates that the line is a comment, i.e., documentation for the convenience of humans rather than something on which the system acts. Aliases for the root user (i.e., administrative account) can be made permanent by entering them in the .bashrc file in the root user’s home directory (which is /root), i.e., in /root/.bashrc. System-wide aliases can be put in the /etc/bashrc file. (Note that, at least on some systems, /etc/bashrc is not a hidden file.) The system needs to be restarted before system-wide aliases can take effect. If the unalias command, which is used to remove or suppress aliases, is used on an alias which has been recorded in a .bashrc file, that alias is turned off for the duration of the current login session. However, the alias is not removed from the .bashrc file, and when the user logs in again, that alias is again in effect. Created August 6, 2005. Copyright © 2005 The Linux Information Project. All Rights Reserved. |
||
| http://www.linfo.org/make_alias_permanent.html |
Migrating to ubuntu (again)
Apr 24th
After long time not using linux for desktop (i usually manage linux for servers) , even though i need to moved some of my data to DVD, finally i install (again) ubuntu on my desktop.
Im trying to migrate (again) to linux since i rarely use my desktop pc anymore for work, probably i’ll try to setup my own server own this box and have an experimental things done in this box.
I often says (again) since after i install linux several times on my office desktop, my home desktop, somehow linux has some problems with my hardwares (especially with my office desktop), my guess is my mainboard (ECS NForce 4M-A) or my video card (gigabyte x3100) causes all the problems.
Even yesterday i needed to do several times effort to install, since the installer had some errors several times before it succeeded.
Well, lets see how long this install will last