March11
In linux we can easily get the last executed command using the below command.
echo “!!”
execute the last executed command by simply typing two !!
!!
you can easily redirect the output into one more script file.
echo “!!” > test.sh
March11
Create a simple shell script as follows.
echo “Hello World”
save the file as hello_world
And now you can see the file permission using the ls -l command.
$ ls -l hello_world
-rw-r–r– 1 kamaraj kamaraj 19 2011-03-11 20:40 hello_world
Now type sh hello_world in the terminal.
$ sh hello_world
hello world
February19
$1 - $9 these variables are the positional parameters.
$0 the name of the command currently being executed.
$# the number of positional arguments given to this
invocation of the shell.
$? the exit status of the last command executed is
given as a decimal string. When a command
completes successfully, it returns the exit status
of 0 (zero), otherwise it returns a non-zero exit
status.
$$ the process number of this shell - useful for
including in filenames, to make them unique.
$! the process id of the last command run in
the background.
$- the current options supplied to this invocation
of the shell.
$* a string containing all the arguments to the
shell, starting at $1.
$@ same as above, except when quoted.
January17
Hi All,
Here is the new utility called cpulimit
What is it ?
cpulimit is a simple program which attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don’t want them to eat too much cpu. It does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.
how to get it ?
sudo apt-get install cpulimit
or
Download it from http://cpulimit.sourceforge.net/
How to use it ?
cpulimit -e <process-name/PID> -l 30
Example:
cpulimit -e 2223 -l 30
cpulimit -e firefox -l 50
Thanks & Bye
Kamaraj
January16
Hi All,
Now we are gonna check the particular website is up or not. For that we need the lynx command
lynx is a general purpose distributed information browser for the World Wide Web
if you don’t have command in your OS, then you can download and install it from the below URL
http://lynx.isc.org/
or if you use the ubuntu, then execute the below command
sudo apt-get install lynx
Once it is installed, you can try the below program.
$ cat website_test.sh
lynx -dump $1 &> /dev/null
if [ $? = 0 ]
then
echo “website is up”
else
echo “website is down. Trigger the email”
fi
Output :
$ ./website_test.sh http://google.com
website is up
$ ./website_test.sh http://google32323232.com
website is down. Trigger the email
January11
Here is the trick to create the show desktop icon for the ubuntu operating system.
Make sure you already having the utility called xte. (type xte in the console and check whether it is already exists or not), If not, then do
sudo apt-get install xautomation
The above command will automatically install the xte utility.
or download the debian package from the below website and install manually.
http://in.archive.ubuntu.com/ubuntu/pool/universe/x/xautomation/xautomation_1.03-1_i386.deb
now goto the desktop and right click –> choose “create launcher”
Type: Application
Name : Show Desktop
Command : xte “keydown Control_L” “keydown Alt_L” “key d” “keyup Control_L” “keyup Alt_L”
Comment : Show Desktop
press ok to create the launcher, and drag the launcher to your gnome panel. That’s all. you created the show desktop icon for your ubuntu.
Enjoy and let me know if you face any problems.
December29
Hi All,
Hope all of you familiar with grep command. Here is one more trick to solve the crossword puzzle using the grep command and the dictionary file.
1
2
3
4
5
6
7
8
9
10
11
| $ grep "^.ro..w.r.$" /usr/share/dict/words
broomwort
brownwort
crossword
crosswort
crownwork
crownwort
frontward
frostwork
frostwort |
$ grep "^.ro..w.r.$" /usr/share/dict/words
broomwort
brownwort
crossword
crosswort
crownwork
crownwort
frontward
frostwork
frostwort
Just replace unknown character by . (dot) in the grep command.
bye
kamaraj
December19
watch is used to run any designated command at regular intervals. It displays its output on a console (i.e., all-text mode display) or terminal window (i.e., a window in a GUI that emulates a console) that is temporarily cleared of all other content (i.e., prompts, commands and results of commands).
This makes it easy to observe the changing output of a command over time.
Example :
watch -d free -m
watch command will observe the free command and it will highlight the difference for each 2 seconds.
Output:
Every 2.0s: free -m Sun Dec 19 01:24:29 2010
total used free shared buffers cached
Mem: 1498 1038 459 0 48 644
-/+ buffers/cache: 345 1152
Swap: 1398 0 1398
December19
TELNET (TELecommunication NETwork) is a network protocol used on the Internet.
TELNET is a client-server protocol, based on a reliable connection-oriented transport. This command will help us to find if a particular port on the server is open or not.
Example:
In the below example i am checking whether port # 22 is open or not in my system
[kamaraj@Kamaraj ~]$ telnet 127.0.0.1 22
Trying 127.0.0.1…
Connected to 127.0.0.1.
Escape character is '^]'.
SSH-2.0-OpenSSH_5.5
If you get the above message "Connected to 127.0.0.1" then it is open. If you get a message like "connection refused" then it the port is not open.
December19
ps command:
This command is used to check the process running on the server. " ps " command will list all the running process with there respective process ID.
:
This command is also used the check the process on the server. " pstree " command will list all the running process in the form of a tree structure.
init─┬─NetworkManager─┬─dhclient
│ └─2*[{NetworkManager}]
├─abrtd
├─acpid
├─atd
├─auditd─┬─audispd─┬─sedispatch
│ │ └─{audispd}
│ └─{auditd}
├─avahi-daemon───avahi-daemon
├─bluetoothd
├─bonobo-activati───2*[{bonobo-activat}]
├─clock-applet───{clock-applet}
├─console-kit-dae───4*[{console-kit-da}]
├─crond
├─cupsd
Also try the -p option for pstree
[kamaraj@Kamaraj ~]$ pstree -p
init(1)─┬─NetworkManager(1160)─┬─dhclient(2091)
│ ├─{NetworkManager}(1174)
│ └─{NetworkManager}(2092)
├─abrtd(1441)
├─acpid(1288)
├─atd(1474)
├─auditd(1629)─┬─audispd(1631)─┬─sedispatch(1643)
│ │ └─{audispd}(1644)
│ └─{auditd}(1630)
├─avahi-daemon(1178)───avahi-daemon(1179)
├─bluetoothd(1388)
├─bonobo-activati(1824)─┬─{bonobo-activat}(1832)
│ └─{bonobo-activat}(1933)
├─clock-applet(2069)───{clock-applet}(2074)
├─console-kit-dae(1532)─┬─{console-kit-da}(1533)
│ ├─{console-kit-da}(1534)
│ ├─{console-kit-da}(1536)
Recent Comments