Skip to main content

Posts

Showing posts with the label linux

Control Linux Box using Terminal

You can shutdown, restart a linux box from Terminal. You can use the following commands to do so Open Terminal Type in “ sudo restart ” to restart the system Sometimes you may get the error “command restart not found” if you get this error then try the commands using sudo /sbin/restart or sudo /sbin/shutdown –r now   Get more help on shutdown command using man shutdown

wget error–“zsh: parse error near &”

There is no doubt that I prefer wget way over any other type of downloads… Syntax: wget <DOWNLOAD_URL>   If you get this error “ zsh: parse error near & ” then its probably because your download URL has a “&” so you should try giving your DOWNLOAD_URL in double quotes wget “<DOWNLOAD_URL>”   If you are trying to download from a site which needs you to give your credentials then you can try giving it this way wget --http-user=<UserName> --http-password=<Password> “<DOWNLOAD_URL>”   Hope this helps

Shell Script to Check if Selenium Server is Running!

Many a times we would want to write up a script to start the selenium server using a shell script… So here is the script     #!/bin/sh # # @Author – Sirisha # @Date   - May 29 2012 # Script to start the Selenium Server on a given host #   # Defined the hostname hostname=somehostname # Defined the path to the selenium server serverPath=~/seleniumServer/ # Define the Selenium Server version jar server=selenium-server-standalone-2.12.0.jar # Define the Search String for the server SERVICE_STRING="'java -jar $server'"   # Clear the terminal clear   echo "service string is: $SERVICE_STRING" echo "Starting Selenium Server on $hostname"   # Run the command to get the process list ps -ef | grep -v grep | grep selenium   # Check if the Selenium Server is already running if [ $? -eq 0 ] then     echo "$server is running, everything is fine" else     echo "$server is not running"  ...

How does Shell find out which command/script I am trying to execute?

This is nothing new but yet I thought why not document it so that its etched into my memory (Ya I know I am selfish ) When you run a command or try executing a shell script, the shell first tries to look if your script is found in the Current Directory. To execute a shell script you should be in the same directory where it was created/written. Now this isn’t possible always – so what to do? There are two ways:   Method 1 - When you are executing the script, give the full path to the script! Now if you go by the usual file/folder structure in most of the software engineers – you can go crazy with the paths – the depth at which the script is found can drive you insane   So thankfully we have another way   Method 2 - Add the folder of your script to the PATH variable. What I suggest is create a folder for all your scripts – say myScripts and then add this to your PATH variable. If you are new to using the PATH variable, I suggest you go through this link on PATH ...

Useful Linux Commands - IV

who : gets all the connections made to your account netstat –antp : to know all the process running on ports sudo /etc/init.d/network restart : restart networking on your linux box Understanding the init.d Directory – This directory has the control scripts for most of the services on our linux box. The start/stop/restart/reload/force-reload options can be used with any command found under this directory Most common Services controllable from this directory are: apache2, sshd, networking, ftpd, samba, mysql You can run any command using the following format: sudo /etc/init.d/<command> <option> where command can be apache2, sshd, networking etc and option can be start, stop, restart etc For ex: sudo /etc/init.d/networking restart Simple! Refresh DNS Cache Ping your linux box using “ ping <your_computer_name> ” – Note down the IP Address shown Look at the contents of ifconfig file using “ sudo /sbin/ifconfig ” – Read the part labeled as inet addr: The t...

Useful Linux Commands - III

Here are some useful linux commands... whoami - This command gives you the userid you are logged in as pwd - print working directory. When you type in this command it tells you which folder you are in and along with printing the path of the folder ls - listing. This command will list out all the files and directories under the current directory sorted alphabetically ls -F - This command lists all the files and directories with directories displayed with a trailing slash and executables have a * at the end of the executable name ls -s - lists file sizes - displays in disk blocks ls -s -h lists file sizes with human readable file sizes wc - word count displays lines, words, characters for a particular file wc -c  wc -w wc -l cat - concatenate - prints the file contents one after another sort - sorts the output  head - - gets the topN results from a file mv - move - moves a file cp - copy - copies a file rm - removes a file rmdir - removes a directory cd - ch...

Useful Linux Commands - III

To know your hostname type hostname To know the shell we are working in ps -p $$ This command would give a result: PID TTY          TIME CMD 15362 pts/3    00:00:00 zsh echo $SHELL This command would give a result like: /bin/zsh Please note that once you export your PATH variable or any other env variable, you should restart your terminal to see the changes To create links between the files we can use "ln" To view the current processes which are Running:  ps -ef | more To find out how much free memory (RAM) we have on our linux box: free This command will give the used, swap, free memory on our linux box Also the output is in bytes free -g This command will give the used, swap, free memory on our linux box in GB's To find out the disk space usage data:  df -k  This commands gives output in bytes df -h  This gives the output in GB's 

Useful Linux Commands - I

Want to know your system name? /bin/uname -n Know where you are in your file system:  pwd  The command will print Present Working Directory How do you create a shortcut in linux? ln How to extract compressed files? tar Downloading from a link can't be faster on any other OS :)  wget Forgot which commands you ran? history Want to see whats your disk space usage? df  df -h gives human formatted listing Most important command to know more about the above commands - Need more help about the commands? man

Linux Version Help

Want to know which version your linux box is? Simple question isn't it... Run the following commands: cat /etc/*-release - This will give the distro of your linux For Ex: for RHEL 5 it will give:  Red Hat Enterprise Linux Server release 5 (Tikanga) lsb_release -a - The lsb_release command displays certain LSB (Linux Standard Base) and distribution-specific information For Ex:    LSB Version: :core-3.1-ia32 Distributor ID: RedHatEnterpriseClient Description: Red Hat Enterprise Linux Client release 5.4 (Tikanga) Release: 5.4 Codename: Tikanga uname -mrs - this will give you your kernel version for ex: Linux 2.6.32-5-amd64 x86_64 where:  Linux - Kernel name 2.6.32-5-amd64 - Kernel version number x86_64 - Machine hardware name (64 bit)

Set PATH

Whatever role you are into, this task comes to you eventually where you have to setup your environment! Setting up your classpath/path including... So here is how you can do it! Two ways: Method one - Setting up the path just for the particular session For LINUX: export PATH=$PATH:/home/gvsiri/apache-ant-1.8.2/bin For Windows: set PATH=%PATH%;.;C:\SirishaGV\Software\apache-ant-1.8.2\bin Method two - setting up the path for the profile For Linux: Modify the .bash_profile file For Windows: Change in the environment variables