MRKAVANA (mrkavana@gmail.com) - www.facebook.com/kavanathai
Showing posts with label bashshell. Show all posts
Showing posts with label bashshell. Show all posts

Sep 21, 2011

Change Bash Color in Linux

Add this following line in to :  '/etc/bashrc'

PS1='\[\033[04;33m\]\t\033[00m\]-\033[04;32m\]\u\033[04;33m\]@\033[04;31m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'

Example:


Sep 8, 2011

How to schedule tasks on Linux using the 'at' command


Scheduling jobs is an essential part of administering Linux servers. We took a look at how to schedule jobs on Linux machine using the cron command earlier. Here’s an alternative to cron – at. The primary difference between the two is that when you schedule a task using cron it execute repeatedly without the need for rescheduling. With at, on the other hand, the scheduling of a task is only for a single execution. Both of these commands have their use, and I would suggest that you get a good understanding of them both.
Let’s look at how to schedule a task to execute only once using the at command. First make sure that the at daemon is running using a command like this:
# ps -ef | grep atd
root 8231 1 0 18:10 ? 00:00:00 /usr/sbin/atd
If you don’t see atd running start it with this command:
# /etc/init.d/atd start
Once the daemon has been started successfully you can schedule an at task using the two options -f, for the file to be executed, and -v, for the time at which it should be executed. So if you want to execute the shell script shellscript.sh at 6:30 PM you would run the following command:
# at -f shellscript.sh -v 18:30
Remember that with the at command the script shellscript.sh will execute at 6:30 PM and then the scheduling will disappear. So if this is not what you desire, you are better off using cron.
The at command is pretty clever in that it can take some orders in English if you like. For example, you can schedule jobs using the following syntax as well:
# at -f shellscript.sh 10pm tomorrow
# at -f shellscript.sh 2:50 tuesday
# at -f shellscript.sh 6:00 july 11
# at -f shellscript.sh 2:00 next week

How to format and mount a USB hard drive in Linux


I bought a new USB hard drive the other day. I wanted to use it to create backups of myLinux server. Here’s how I went about formatting and mounting the drive on my Linuxserver.
The first thing I did was to find out where the disk had been mounted. For that I ran the following command:
# tail -F /var/log/messages
When I plugged in the drive into my server there was a message saying the the drive was available at /dev/sdc1. So the next step was to format the drive. There are a number of file formats that can by read and written to by Linux, but Windows is a bit more fussy about it. So I decided to use a tried and tested file system that works well with both operating systems. I went with FAT. So to format the drive as FAT I ran the following command:
# mkfs.vfat /dev/sdc1
In a few minutes the newly formatted drive was ready to go. Now I wanted to mount it. So I created a directory to mount it:
# mkdir /media/usbdisk
Now, to mount the drive to this mount point I ran the following command:
# mount -t vfat /dev/sdc1 /media/usbdisk
And that’s it. My new hard drive was formatted, mounted, and ready to go. I copied the data I wanted to copy on it and then I unmounted it:
# umount /media/usbdisk
NOTE: this last step is very important. If you unplug your drive without unmounting it you could risk the data it holds.
If this is a USB storage device that you might use often and plan to leave it hooked up to your Linux server you can set up the device to be automatically mounted when you boot into Linux. To do that make an entry like the one shown below at the end of file /etc/fstab:
/dev/sdc1 /mnt/usbdrive vfat defaults 0 0
Now your drive will be automatically mounted to your Linux server, and you can take your backups without worrying about mounting a device.

How to create a symlink (shortcut) in Linux


Symlinks or symbolic links are the Linux equivalent of shortcuts in Windows. Creating symlinks of files or folders can be quite useful in Linux, as you can shorten a path such as/var/www/html/application/configuration/images/config.php to something easier to remember and manage such as /var/www/html/image-config.php. Let’s see how this can be done.
Use the following command to create such a symlink:
# ln -s /var/www/html/application/configuration/images/config.php /var/www/html/image-config.php
What we have done here is that we have created a symbolic link, /var/www/html/image-config.php, to /var/www/html/application/configuration/images/config.php. You can verify if the symlink was created correctly by running the following command:
# ls -all /var/www/html/image-config.php
lrwxrwxrwx 1 calvin calvin 37 Apr 29 16:41 image-config.php -> /var/www/html/application/configuration/images/config.php
If you are administering a Linux server symlinks can make your life a lot easer and it is something you should definitely familiarize yourself with. The easy way to remember the symlink syntax is:
# ln -s <source> <destination link>