user-avatar
Today is Saturday
April 20, 2024

Tag: script

March 24, 2010

Custom icons to your script

by viggy — Categories: tech — Tags: , , , Leave a comment

I have to use VNC many times for my work. Everytime to invoke vncviewer, I had to press -F2 and then type “vncviewer”. I didnt want to do this and hence I thought I will write a simple shell script which I can use to run whenever I needed vncviewer. Hence I wrote following two lines in a shell script.

#!/bin/bash
vncviewer

This I saved on my desktop and used to double click it whenever I needed to run it. However even this used to ask me if I wanted to run it or display it. Also the script had a default icon which I didnt want and wanted it to have the icon of vnc. Also I didnt like it to occupy my desktop area and wanted to keep it on my panel. Hence i searched on google for answers. i found the following mail which gave me a clear idea of how to do it.

http://linux.derkeiler.com/Mailing-Lists/KDE/2009-04/msg00131.html

You can create your own icons by creating a textfile and giving it a .desktop
extension. That’s all an icon is. Go to /usr/share/applications and have a look.
Anyone of those files can be dragged into you ~/Desktop folder if you use that for
desktop icons or else directly onto your desktop.

The format of the .desktop file is fairly simple to follow I have made them for
url as well as script icons and keep them in /usr/local/share/applications. Once
you have created the file the “icon” can be used like any other icon, e.g. adding
to Quicklaunch. Use anything for an icon. Here is what one of mine looks like.

[root@localhost ~]# cat /usr/local/share/vncviewer.desktop
[Desktop Entry]
Name=Vncviewer
Comment = runs vncviewer script
Exec=/usr/local/bin/vncviewer.sh
Icon=/usr/share/icons/vncviewer.jpeg
Terminal=0
Type=Application
Categories=Application;Internet;

Hence now I could drag this icon on my panel and launch vncviewer in just one click.
:)

November 12, 2009

a shell script to check if a ipaddress is taken using ping

by viggy — Categories: tech — Tags: , , , Leave a comment

With the help of Abhas Bhaiyya, I could write this shell script which checks if an ipaddress can be pinged.

#!/bin/sh

if [ `ping -c1 192.168.31.31 >/dev/null; echo $?` -eq 1 ]
then
echo “not able to ping”
fi

/dev/null is used here so that the output of the ping command is not compared with 1.
$? gives out the return code of the command.

November 12, 2009

how to get the last argument from the last command in the shell

by viggy — Categories: tech — Tags: , , , , Leave a comment

‘!$’ is the right answer.

For example: $vim test.pl
$chmod +x !$
$./!$

So what is happening above is
first vim test.pl opens a file.
then after you have written a perl script, you would like to make it executable. There is no need for you to specify the file name again. You can just use !$.
In the third command again to execute the file, there is no need to mention the file name again. You just use !$ again.