Archive for Linux

Basic Linux Commands List

man Get help.
cd Move to a different directory.
pwd Print working directory.
find Search directories for matching files.
whereis Find files from files directories.
locate Locate files from locate’s database - locatedb.
updatedb Update locatedb database.
whatis Get command summaries.
makewhatis Build the whatis database (db of command summaries).
apropos Search for whatis database to get the program you want.
ls List files and directories.
dir List directories.
tree List graphic directory.
cat List, create, and combine files.
more Read files.
less Read files (allows scrolling, have more options than the more command).
head,tail Read the beginning and the end of files.
touce Create files.
rm Delete files.
mkdir Create directories.
rmdir Removing directories.
mv Rename files.
cp Copy files.
ln Create hard and symbolic links.
mc Visual shell that display files.
grep, egrep, fgrep, zgrep Search inside files (zgrep can search compressed files).
tar Create archives file.
cpio Copy files in and out of tar or cpio archives.
gzip, gunzip Compress and uncompress files.
compress Compress files.
ps Process status command.
kill Terminate a process.
Ctrl-z Put a running program into background in bash shell.
fg Bring back a program from background.
pine A Linux mail program.
job Get a list of suspended programs.
sc A Linux spreadsheet program.
mount, umount Mount or unmount a file system.

Comments

Writing a Shell Script that executes Locally OR Remotely

There are a lot of times when it is useful to have a single shell script run both upon the local host, and also upon remote hosts. Here we’ll show a simple trick which allows you to accomplish this easily.

To execute shell scripts remotely the most obvious approach is to copy it there, with scp, and then use ssh to actually execute it. This is similar to running simple commands remotely using ssh directly:

skx@mine:~$ ssh yours uptime
07:12:25 up 3 days, 18:15,  0 users,  load average: 0.00, 0.00, 0.08
skx@mine:~$

With that in mind the solution becomes:

  • Write a simple shell script which will be useful.
  • Determine whether it should run remotely, and if so:
    • Copy itself there.
    • Execute itself there.

As an example we’ll look at a simple script which will report upon the uptime of the system it is executed upon:

Here is the script:

#!/bin/sh

#
#  Are we installing locally?  Or remotely?
#
if [ ! -z $1 ]; then

#  Hostname
host=$1

#  Create a secure temporary file.
file=`mktemp`

#  Create a temporary file, and copy the contents of ourself into
# it.  Making sure it has a shebang.
echo "#!/bin/sh"                > "${file}"
grep -A2000 '^#-=-MARKER-=' $0 >> "${file}"
chmod 755 "${file}"

#  Copy the file to the remote host, and invoke it
scp "${file}" ${host}:
ssh "${host}" ./`basename ${file}`

#  Cleanup remotely and locally.
ssh "${host}" /bin/rm `basename ${file}`
rm ${file}

#  All done - the rest of the script will occur remotely.
exit
fi

## THE NEXT LINE IS IMPORTANT     - DO NOT EDIT.  DO NOT REMOVE.
#-=-MARKER-=-
## THE PREVIOUS LINE IS IMPORTANT - DO NOT EDIT.  DO NOT REMOVE.

uptime

Here you can see that the script detects whether to run remotely or not based upon the presence of a command line argument, so this is local execution:

skx@mine:~$ ./uptime.sh
14:05:10 up  4:59,  4 users,  load average: 0.05, 0.05, 0.07

Whereas this is remote:

skx@mine:~$ ./uptime.sh cfmaster.my.flat
tmp.RRjRSx9137                                100%   98     0.1KB/s   00:00
14:05:28 up 430 days, 20:02,  0 users,  load average: 9.72, 6.58, 4.26

Neat huh?

The key to this script is that it can separate out the “real” work of the script so that only the end of the script is copied to the remote host - the part after the argument processing. This is achieved with the following command:

grep -A2000 '^#-=-MARKER-=' $0

This uses the “-A” option of GNU grep to cause it to print out a number of line after the line beginning “#-=-MARKER-=” - this is the part of the script that actually reports on the system uptime, and this is the part you’d replace with your own code.

The relevant lines are then placed into a temporary file and copied to the host upon which it should execute them. (If you didn’t have key-based authentication setup you’d be prompted for your password three times; the first time for the copy, the second time for the execution, and the final time to cleanup the file which was copied.)

Using a simple system like this you could easily write scripts that would preform tasks like installing CFEngine locally or remotely.

Comments

Installing Vmware Server on Debian Etch 4.0

To install VMware server on Debian Etch (4.0) you first need to have Etch installed on you host PC, you can achieve this by using the netinst CD available at: http://www.debian.org/devel/debian-installer/ Once you have it installed you can proceed with this How To install VMware server on Debian Etch

1.- First install some software needed (as root)

apt-get install libx11-6 libx11-dev libxtst6 xinetd wget

apt-get install linux-headers-`uname -r` build-essential

apt-get install binutils-doc make manpages-dev autoconf automake1.9 libtool flex bison gdb libc6-dev-amd64 lib64gcc1 gcc-2.95-doc

apt-get install gcc apt-get install g++

(Thanks to Marga: read here 2.- Get the Software You can get the vmware server here: http://www.vmware.com/download/server/ and do not forget to obtain the serial number by registering here: http://register.vmware.com/content/registration.html

3.- Installation You can use wget, to get the appropiate code, or any mean you prefer, once you have the .tar.gz file tar xvzf [package_downloaded] cd vmware-server-distrib ./vmware-install.pl here you just need to press enter, enter, enter to all questions, unless you want a more presonalized configuration, i.e. if you have two NICs and want both of the bridged to vmnet0 and vmnet2 as in my case, just follow the instructions in the script.

4.- Patching the software As Etch has a newer version of Kernel the VMware server needs to be patched, here is how.

– Get the code Download from here: http://jaws.go2linux.org/archivos/vmware-any-any-update109.tar.gz

– Unpack it tar xvzf vwmare-any-any-update108.tar.gz

– Change to its directory cd vwmare-any-any-update108

– Run the script that is going to patch the VMWare.

./runme.pl 5.- Automatic start vmware at start update-rc.d vmware defaults 20 Enjoy your vmware server installed on your Debian 4.0 Etch

Original Article Source: http://www.go2linux.com/

Comments (2)