Monday, October 5, 2009

The 7 Deadly Linux Commands

The 7 Deadly Linux Commands

Shared via AddThis

Wednesday, July 1, 2009

Kill process in Linux or terminate a process in UNIX or Linux systems

Kill process in Linux or terminate a process in UNIX or Linux systems

Q. How do I kill process in Linux?

A. Linux and all other UNIX like oses comes with kill command. The command kill sends the specified signal (such as kill process) to the specified process or process group. If no signal is specified, the TERM signal is sent.
Kill process using kill command under Linux/UNIX

kill command works under both Linux and UNIX/BSD like operating systems.
Step #1: First, you need to find out process PID (process id)

Use ps command or pidof command to find out process ID (PID). Syntax:
ps aux | grep processname
pidof processname

For example if process name is lighttpd, you can use any one of the following command to obtain process ID:
# ps aux | grep lighttpdOutput:

lighttpd 3486 0.0 0.1 4248 1432 ? S Jul31 0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf
lighttpd 3492 0.0 0.5 13752 3936 ? Ss Jul31 0:00 /usr/bin/php5-cg

OR use pidof command which is use to find the process ID of a running program:
# pidof lighttpdOutput:

3486

Step #2: kill process using PID (process id)

Above command tell you PID (3486) of lighttpd process. Now kill process using this PID:
# kill 3486
OR
# kill -9 3486
Where,

* -9 is special Kill signal, which will kill the process.

killall command examples

DO NOT USE killall command on UNIX system (Linux only command). You can also use killall command. The killall command kill processes by name (no need to find PID):
# killall -9 lighttpd
Kill Firefox process:
# killall -9 firefox-bin
As I said earlier killall on UNIX system does something else. It kills all process and not just specific process. Do not use killall on UNIX system (use kill -9).

Stock Quotes on your Desktop with Conky

Stock Quotes on your Desktop with Conky

by Bhavik | February 27, 2009 | In Linux | 435 views

I wrote another script today to save me from needing to open up a browser.
The old process for stock quotes was, go to yahoo, type in each stock, get the price.
The new process involves only directing my attention to the bottom right corner of my desktop. All stocks of interest are lined up inside my conky. They auto refresh every 2 minutes for me. I can see the current value, what it opened at, and the change.

If you don’t know what conky is click here for my conky tutorial.

To get it working, download the script and add the following line to your .conkyrc

${execi 120 python /path/to/script/stocks.py stock1 stock2 stock3}

Replace 120 with your interval, use your path to the script, and change the stocks to actual stock quotes.
Example:

{execi 120 python /home/bhavik/scripts/stocks.py goog msft aapl}

Hope it helps any of the linux users out there that also like to trade =)

Changes:
3/5/09 - Removed decimal conversion to float…
If the market was closed the value was N/A.
Since you can’t convert a string to float it was getting errors.
Should be good now.

Screenshot
conky_stocks_screenshot
by Bhavik | February 27, 2009 | In Linux | 435 views

I wrote another script today to save me from needing to open up a browser.
The old process for stock quotes was, go to yahoo, type in each stock, get the price.
The new process involves only directing my attention to the bottom right corner of my desktop. All stocks of interest are lined up inside my conky. They auto refresh every 2 minutes for me. I can see the current value, what it opened at, and the change.

If you don’t know what conky is click here for my conky tutorial.

To get it working, download the script and add the following line to your .conkyrc

${execi 120 python /path/to/script/stocks.py stock1 stock2 stock3}

Replace 120 with your interval, use your path to the script, and change the stocks to actual stock quotes.
Example:

{execi 120 python /home/bhavik/scripts/stocks.py goog msft aapl}

Hope it helps any of the linux users out there that also like to trade =)

Changes:
3/5/09 - Removed decimal conversion to float…
If the market was closed the value was N/A.
Since you can’t convert a string to float it was getting errors.
Should be good now.

Screenshot
conky_stocks_screenshot

Monday, June 29, 2009

Adding REAL Firefox to Debian Lenny

Adding REAL Firefox to Debian Lenny
December 26th, 2008


This procedure assumes you’ve downloaded and installed the latest Debian Lenny (aka “testing,” currently) GNU/Linux distribution, along with its standard GNOME desktop environment.

* Using Iceweasel for the last time, download Firefox to your home directory. Let’s assume the name of the file you downloaded is “firefox-3.0.5.tar.bz2″ (the current version as of this writing).

* Open up a terminal window and, as root, type the following commands (following each by hitting Enter):
apt-get remove iceweasel
mv firefox-3.0.5.tar.bz2 /usr/lib/
cd /usr/lib/
tar -jxvf firefox-3.0.5.tar.bz2
ln -s /usr/lib/firefox/firefox /usr/bin/firefox

If you prefer, you can simplify the above commands by copying/pasting the following text onto your terminal command line:
apt-get remove iceweasel; mv firefox-3.0.5.tar.bz2 /usr/lib/; cd /usr/lib/; tar -jxvf firefox-3.0.5.tar.bz2; ln -s /usr/lib/firefox/firefox /usr/bin/firefox

* Finally, you’ll need a launch icon on your desktop. You can create that the standard way GNOME allows, or simply save this file to your GNOME desktop.

That’s all there is to it!

Well, one other point. To make use of browser plugins that have already been set up by your Debian installation, you’ll want to create a symlink from /usr/lib/firefox/plugins/ to /usr/lib/mozilla/plugins/, using this two-part command (as root):

rm -rf /usr/lib/firefox/plugins; ln -s /usr/lib/mozilla/plugins /usr/lib/firefox/plugins

Incidentally, on my installation, the default flash plugin that came with Lenny (flash-mozilla.so) required me to click a large play button (shown at right) each time I visited a web page that used flash. So, I went to Adobe’s flash plugin download page and downloaded the flash plugin for debian, then installed it with the command “dpkg -i install_flash_player_10_linux.deb” (as root). That plugin (flashplugin-alternative.so) works much better.

Monday, June 22, 2009

Convert .avi, mp4 etc to dvd.iso

AVI to DVD Script (Linux - Ubuntu)




You need to install...

mencoder (sudo apt-get install mencoder)

ffmpeg (sudo apt-get install ffmpeg)

dvdauthor (sudo apt-get install dvdauthor)

Now make a new file and paste this in:

#!/bin/bash
## Movie - AVI to DVD Script
## Created by Paul (realtimeedit.com/blog/), 7th October 2007.
echo "Directory?"
read output_file_directory
echo "AVI file name for conversion?"
read input_file_one

##START
cat $input_file_one > dvd.avi
mencoder -o finalmovie.avi -noidx -oac copy -ovc copy dvd.avi
ffmpeg -i finalmovie.avi -y -target ntsc-dvd -sameq -aspect 16:9 finalmovie.mpg
dvdauthor --title -o dvd -f finalmovie.mpg
dvdauthor -o dvd -T
mkisofs -dvd-video -o dvd.iso dvd/
echo "Now burn dvd.iso to a DVD"
##END

Save that as dvd_script in the same folder as the AVI

Now open terminal and use this command to go to the folder you just saved dvd_script in.

cd /path/of/movie/folder/

Then we can run the script.
Type this in terminal:

./dvd_script..note: if you get a permisson error run the script by typing sh dvd_script


It should say “Directory?”, then enter where the file is eg, “/home/user/movie/”

Then press enter and put in the file name eg, “thematrix.avi”

Now let it go. It should take some time, unless you’re on a computer from the future.

After that you can put “dvd.iso” onto a DVD with the program of your choice.

Note: dvd_script will make the dvd files in the folder it is in.


1. joe Says:
October 9th, 2007 at 6:56 pm

you could use a program in the repositories called DeVeDe which is pretty good
2. Paul Says:
October 9th, 2007 at 7:06 pm

I’ve never used that before, I’ll give it a look later :)
Thanks
3. Ford Prefect Says:
October 16th, 2007 at 2:06 pm

Why do you make two steps?

mencoder -o finalmovie.avi -noidx -oac copy -ovc copy dvd.avi

ffmpeg -i finalmovie.avi -y -target ntsc-dvd -sameq -aspect 16:9 finalmovie.mpg

What happens if you give the original avi file directly to ffmpeg?

Thanks!
4. Paul Says:
October 16th, 2007 at 5:52 pm

That’s there for people who want to put more than one AVI file into the final movie.
For example, cat $input_file_one $input_file_two > dvd.avi

mencoder -o finalmovie.avi -noidx -oac copy -ovc copy dvd.avi
Will sync the sound with the video.
I suppose you could take out the ‘mencoder’ line, but I haven’t tried it yet.

Thanks :)
5. Mr.C Says:
October 17th, 2007 at 8:14 pm

if u remove the mencoder line and put your avi streight into ffmpeg u will have really poor fps while converting in my experience
6. JohnsonFarms Says:
October 21st, 2007 at 7:53 pm

how do you input more than 1 .avi at a time?
7. Paul Says:
October 21st, 2007 at 9:21 pm

##AFTER
echo “AVI file name for conversion?”
read input_file_one

##ADD
echo “Second file?”
read input_file_two

##ON LINE
cat $input_file_one > dvd.avi

##CHANGE TO
cat $input_file_one $input_file_two > dvd.avi

Basically you just a space on that line and type in the new file name.
8. Stig Says:
October 23rd, 2007 at 3:12 pm

What about PAL dvds? And 4:3 aspect ratios, for that matter?
9. Paul Says:
November 6th, 2007 at 7:35 pm

on line 12: ffmpeg -i finalmovie.avi -y -target pal-dvd -sameq -aspect 4:3 finalmovie.mpg

-target pal-dvd

-aspect 4:3
10. Video To Dvd Transfer Says:
November 15th, 2007 at 8:50 pm

I thought that DVD format in Linux Ubuntu Script | Realtimeedit was very interesting. I found you searching on Video To Dvd Transfer Thursday Thanks for the nice post!
11. Copy Dvd Movies Says:
December 4th, 2007 at 11:43 am

Hey!, I fell blessed that I found your post while searching for copy dvd movies. I agree with you on the subject DVD format in Linux Ubuntu Script | Realtimeedit. I was just thinking about this matter last Tuesday.
12. KA Says:
December 6th, 2007 at 3:04 am

Help, the command line returns Permission denied.

Thank You
13. Dvd To Dvd Copy Says:
December 6th, 2007 at 11:48 pm

Hi, what entice you to post an article on DVD format in Linux Ubuntu Script | Realtimeedit? This article was extremely interesting, especially since I was searching for thoughts on this subject last Thursday.
14. Greg Says:
December 8th, 2007 at 3:22 am

Awesome. Just what I was looking for.
DeVeDe is cool, but it wants mplayer and other things I DON’T want to have to install - I’m a minimalist kind of guy.
15. Burn Dvd Video Says:
December 22nd, 2007 at 1:59 am

It\’s Friday, and I thought that you would like to know I really really really liked this article (DVD format in Linux Ubuntu Script | Realtimeedit). I wasn\’t really looking for this (I was searching on \’burn dvd video\’), but I\’m glad I found your blog as a result. Keep up the great blogging!! I\’ve bookmarked you.
16. Adonis Says:
December 27th, 2007 at 5:37 pm

Adonis…

Interesting stuff. I had a weird experience while movie downloading recently….
17. Greg Says:
January 7th, 2008 at 4:34 pm

It seems to make too big of an MPG file for standard DVD (4.7Gb) how can I reduce the resolution or richness to squeeze 800Mb AVI file onto normal DVD media?
18. How To Copy Dvd Says:
January 11th, 2008 at 11:46 am

Hey!, I fell blessed that I found your post while searching for how to copy dvd. I agree with you on the subject DVD format in Linux Ubuntu Script | Realtimeedit. I was just thinking about this matter last Friday.
19. alexand Says:
May 21st, 2008 at 5:35 am

how I put subtitles?
I have move.avi and move.srt
20. Rob Scott Says:
July 5th, 2008 at 10:42 pm

I got permission denied as well? Any takers?
21. professional Says:
July 19th, 2008 at 3:36 am

Hello. I think you are eactly thinking like Sukrat. I really loved the post.
22. jonny rocket Says:
July 27th, 2008 at 3:33 am

i will try devede. when i’m in windows i use nero vision express. it works great. the nero part, not the windows part. lol.
23. Daniel Says:
August 18th, 2008 at 4:13 am

Hey, Have used this script a few times now, works great. the DeVeDe doesn’t work for me.

Great to have found your script was soo easy to you.

Daniel
24. kris Says:
August 30th, 2008 at 6:42 am

If you have problems with permission denied make shore you are in the correct directory and then type in sh dvd_script.

Kris

(thanks for the script much appreciated)
25. Subzero22 Says:
September 3rd, 2008 at 3:30 am

Well I just installed WineHQ and then installed ConvertXtoDVD. makes it much easier.
26. Jamie Says:
September 9th, 2008 at 4:04 pm

for the guys that are getting

permission denied

try

sudo chmod 755 dvd_script
27. yarn Says:
September 12th, 2008 at 8:08 pm

if it says file permission denied then you have to right click on the original dvd_script file and go to permissions…then check allow file to execute progarm or something to that effect.
28. Hans Says:
October 11th, 2008 at 9:58 pm

He Paul, great stuff, many thanks. It leaves me with only one question: how to take subtitles into account? I have for example cd.avi and cd.srt, the latter containing Dutcj subtitles. Any help appreciated!
29. Legal Movie Downloads Says:
October 27th, 2008 at 8:09 pm

Cool, I was getting that error, thanks for the fix
30. Legal Movie Downloads Says:
November 2nd, 2008 at 7:53 am

Interesting, I’ll use this to convert my movies for sure
31. linuxcrypt Says:
November 21st, 2008 at 2:55 pm

Awesome script! Thanks for taking the time to post it.
32. kjm Says:
November 24th, 2008 at 6:25 pm

WHY NOT JUST LOAD WINFF AND DO IT FROM THE GUI?
33. KronicDreamer Says:
December 29th, 2008 at 5:05 pm

Very nice article! :)

got ubuntu up and wanted to try a few dvd burns…

ty
34. ironjade Says:
January 13th, 2009 at 4:48 pm

The latest version of DeVeDe has a disc usage button which will automatically fit the image to the disc so no more messing with bitrates etc. DeVeDe is one of the most useful Linux apps ever.

Thursday, May 14, 2009

Debian Lenny Samba Standalone Server

Debian Lenny Samba Standalone Server With tdbsam Backend

This tutorial explains the installation of a Samba fileserver on Debian Lenny and how to configure it to share files over the SMB protocol as well as how to add users. Samba is configured as a standalone server, not as a domain controller. In the resulting setup, every user has his own home directory accessible via the SMB protocol and all users have a shared directory with read-/write access.

I do not issue any guarantee that this will work for you!


1 Preliminary Note

I'm using a Debian Lenny system here with the hostname server1.example.com and the IP address 192.168.0.100.


2 Installing Samba

Connect to your server on the shell and install the Samba packages:

aptitude install libcupsys2 samba samba-common

You will see the following questions:

Workgroup/Domain Name: <-- WORKGROUP
Modify smb.conf to use WINS settings from DHCP? <-- No

Edit the smb.conf file:

vi /etc/samba/smb.conf

In the global section, remove the "#" at the beginning of the line security = user so it looks like this:

[...]
# "security = user" is always a good idea. This will require a Unix account
# in this server for every user accessing the server. See
# /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/ServerType.html
# in the samba-doc package for details.
security = user
[...]

This enables Linux system users to log in to the Samba server.

Close the file and restart Samba:

/etc/init.d/samba restart


3 Adding Samba Shares

Now I will add a share that is accessible by all users.

Create the directory for sharing the files and change the group to the users group:

mkdir -p /home/shares/allusers
chown -R root:users /home/shares/allusers/
chmod -R ug+rwx,o+rx-w /home/shares/allusers/

At the end of the file /etc/samba/smb.conf add the following lines:

vi /etc/samba/smb.conf

[...]
[allusers]
comment = All Users
path = /home/shares/allusers
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
writable = yes

If you want all users to be able to read and write to their home directories via Samba, add the following lines to /etc/samba/smb.conf:

[...]
[homes]
comment = Home Directories
browseable = no
valid users = %S
writable = yes
create mask = 0700
directory mask = 0700

Now we restart Samba:

/etc/init.d/samba restart


4 Adding And Managing Users

In this example, I will add a user named tom. You can add as many users as you need in the same way, just replace the username tom with the desired username in the commands.

useradd tom -m -G users

Set a password for tom in the Linux system user database. If the user tom should not be able to log in to the Linux system, skip this step.

passwd tom

-> Enter the password for the new user.

Now add the user to the Samba user database:

smbpasswd -a tom

-> Enter the password for the new user.

Now you should be able to log in from your Windows workstation with the file explorer (address is \\192.168.0.100 or \\192.168.0.100\tom for tom's home directory) using the username tom and the chosen password and store files on the Linux server either in tom's home directory or in the public shared directory.


5 Links

* Samba: http://www.samba.org/
* Debian: http://www.debian.org/

Thursday, May 7, 2009

Howto: setup Conky in Hardy and Ibex


Here is some cool code that I've done up which can be added into any homebrew .conkyrc file:

1. This little item is great for figuring out if you've got spy-ware or are being DOS attacked. It will list any programs that are connecting to the outside world, and tell you how many connections they are making:

${execi 30 netstat -ept | grep ESTAB | awk '{print $9}' | cut -d: -f1 | sort | uniq -c | sort -nr}

2. This one will list the latest 3 system log (error, etc) messages on your machine. Great to see if some piece of software or hardware isn't working right:

${execi 30 tail -n3 /var/log/messages | awk '{print " ",$5,$6,$7,$8,$9,$10}' | fold -w50}

3. This one will show if a program is stealing too much CPU or memory or has become a zombie eating up your resources. Good also for diagnosing which program is borking itself if your computer is hanging:

${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}

you can then kill the problem program easily from the command line = "kill [insert pid number]