SHELL-1.1 Shell Script Introduction and Basics


Make sure to subscribe to my channel for more videos on UNIX, Perl and SQL.
facebook: facebook.com/fuzicast
twitter: @fuzicast
youtube: youtube.com/fuzicast

A shell script is basically a script that runs a bunch of unix commands along with conditional statements, loops statements. When programming shell script, space matters.
#!/bin/bash

# SETTING A VARIABLE
greeting=”Hello World”

# SETTING A GLOBAL/ENVIRONMENT VARIABLE
export blogname=”fuzicast”

# ASSIGN OUTPUT OF SUBSHELL TO VARIABLE
filenames=$(ls -ltr) # note that subshell inherits all environment variables from parent shell
no_of_files=`ls -ltr | wc -l`

# HOW TO CREATE MULTIPLE LINE COMMENT
<<COMMENT
The previous line begins a comment block, this is also known as HERE DOCUMENT
Here's another comment
The following line ends the comment block
COMMENT

# PERFORM ARITHMETIC CALCULATION
var1=45
var2=30
echo $[ $var1 + $var2 ]
(( sum=$var1 + $var2 ))
echo $sum

# IF STATEMENT
if [ $[ $var1 + $var2 ] -gt 70 ];then
echo "sum is greater than 70"
elif [ $[ $var1 + $var2 ] -lt 70 ];then
echo "sum is less than 70"
else
echo "unknown"
fi

# WHILE STATEMENT
var1=30
while [ $var1 -gt 0 ];do
echo "while \$var1 is greater than 0, keep running … "
var1=$[ $var1 – 1 ]
done

# UNTIL STATEMENT
var1=0
until [ $var1 -gt 30 ];do
echo "until \$var1 is greater than 30, keep running …"
var1=$[ $var1 + 1 ]
done

# FOR STATEMENT
for arg in $@;do
echo $arg
done

# CASE STATEMENT
var1=1
case $var1 in
1) echo "hello world"
echo "fuzicast video tutorials";;
2) echo "wrong option";;
3) echo "guess again";;
*) echo "Default option";;
esac

Advertisements

Fuzicast hits 5000+ views; New video on UNIX pipes and direction


Wow, after a little more than 2 months since inception of the blog, fuzicast.com now has over 100+ subscribers (twitter, youtube, facebook, wordpress), 5000+ views on the blog and more than 4000+ views on Youtube videos. Is it worth for a celebration? I say yes! But above all, this couldn’t have been done without all the viewers and subscribers. Thank you for making this happen. More videos will be coming out this weekend to celebrate! =)

PS: If you like the blog, please feel free to share fuzicast.com with your friends and coworkers. Also make sure to subscribe to my channel for more videos on UNIX, Perl and SQL.
facebook: facebook.com/fuzicast
twitter: @fuzicast
youtube: youtube.com/yuejdesigner85

UNIX-1.12 SSH Command


Make sure to subscribe to my channel for more videos on UNIX, Perl and SQL.
facebook: facebook.com/fuzicast
twitter: @fuzicast
youtube: youtube.com/fuzicast

ssh username@host – remote login to a remote host
ssh -i ssh-key username@hostname – using another key to ssh remote host
ssh-keygen -t rsa/dsa – generate ssh keys using either rsa or dsa encryption
sudo useradd -m username – create user with home directory created automatically
passwd username – change password for that user
sudo usermod username -s /bin/bash – set type of shell for user
~/.ssh/config – create this config file and add Host, User, Hostname and IdentityFile settings
Host alias_name
Hostname localhost
IdentityFile ~/.ssh/obama.key
User username
ssh-copy-id username@hostname – copy ssh public automatically to remote host
ssh username@hostname ‘remote-command’ – execute remote commands
ssh -F another_config_file username@hostname – specify different config file
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no username@hostname – do not check for known hosts and add host key automatically to known_hosts file. since we set known_host file to /dev/null, new host key will be added to garbage file.