Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, August 7, 2007

Job Scheduling

I love Linux Shell Scripts. That is one of the coolest areas to work with. Traditionally in Windows we used to work with MS DOS commands. But Linux shell scripting interests me the most.

Cron is the infamous buzzword for scheduling jobs. It helps you schedule jobs chronologically. There is another command that helps schedule one-time jobs. Think about it, your machine is used as a server for a lot of people working, connecting to your machine. You will not be there till every one of them finish using your server. Once they finish, your server well needs to be shutdown for maintenance. But as people are selfish, you cant trust them to do the shutdown for you. But well, yes, you can very well trust your program to do that for you.

atd is the the Linux command used to schedule one-time jobs queued for later execution. atd is the service which has to be enabled and running to do this.

Some Examples:




[samjosh@Samjosh ~]$ /sbin/service atd restart





# Schedule system shutdown at 18:20
[samjosh@Samjosh ~]$ at 20:30
at> poweroff
at>
job 16 at 2007-08-16 20:30
[samjosh@Samjosh ~]$





# To see all the jobs in queue
[samjosh@Samjosh ~]$ atq
16 2007-08-16 20:30 a samuelt
[samjosh@Samjosh ~]$

Well then what if all of the clients shutdown before the scheduled time? You need to check constantly whether any of your client is alive. If so, wait... otherwise its safe to power off your machine.

Here are the snippets!




# Checks status of your client
host=192.168.0.118
ping -c 1 $host
if [ `echo $?` -ne 0 ]
then
echo $host" is alive"
else
echo $host" is not alive"
fi

# Tip
Use as in the above snippet for each of your clients. Do this in a while loop. If a client is alive you can continue the loop as follows:




while [ 1 ]
do

{if - host1 is alive }
shift
continue
{else - check for host2 }
....
{if - host n is dead }

echo "System shutdown at `date` " >> ~/Desktop/my_log.txt
poweroff

done


Cool! I luvvit... Samjosh.

Thursday, June 14, 2007

Ripping your audio CD to Mp3

(Fedora Core)

For ripping your audio CD, use Sound Juicer, which can be accessed like this :
Applications->Sound and Video->Sound Juicer CD Ripper

The files are ripped into ogg files by the sound juicer.

The sox and lame that comes with fedora core helps you convert these ogg files to mp3.

So here goes the two step funda:

1) using sox convert your ogg to wav
eg. sox oggfile.ogg wavfile.wav
2) using lame convert this wav to mp3
eg. lame wavfile.wav mp3file.mp3

Go ahead and enjoy the music.

My favourite Mp3 player is mpg123 Go ahead and install one if you dont have. (yum it) then enjoy the light-weight, command-line mp3 layer.

that's for now,
samjosh :)