You can try this
1) Create public key like this
ssh-keygen -t rsa
It will ask u a passphrase, do not give any, just enter
2) Copy te file id_rsa.pub to the $HOME/.ssh directory of the machine you wish to connect to, where $HOME is the directory of the user you would like to connect as. /root/.ssh in the case you would like to connect as root. Consider you would like to connect as the user user
scp $HOME/.ssh/id_rsa.pub usuario@server.remoto:/home/user/.ssh/authorized_keys2
or
ssh-copy-id ~/.ssh/id_rsa.pub username@example.com
# Now you can connect to the remote server with out being asked for a password.
3) ssh -l usuario server.remoto
Search This Blog
Saturday, January 31, 2009
How to login in a remote server using SSH and no password
You can try this
1) Create public key like this
ssh-keygen -t rsa
It will ask u a passphrase, do not give any, just enter
2) Copy te file id_rsa.pub to the $HOME/.ssh directory of the machine you wish to connect to, where $HOME is the directory of the user you would like to connect as. /root/.ssh in the case you would like to connect as root. Consider you would like to connect as the user user
scp $HOME/.ssh/id_rsa.pub usuario@server.remoto:/home/user/.ssh/authorized_keys2
or
ssh-copy-id ~/.ssh/id_rsa.pub username@example.com
# Now you can connect to the remote server with out being asked for a password.
3) ssh -l usuario server.remoto
1) Create public key like this
ssh-keygen -t rsa
It will ask u a passphrase, do not give any, just enter
2) Copy te file id_rsa.pub to the $HOME/.ssh directory of the machine you wish to connect to, where $HOME is the directory of the user you would like to connect as. /root/.ssh in the case you would like to connect as root. Consider you would like to connect as the user user
scp $HOME/.ssh/id_rsa.pub usuario@server.remoto:/home/user/.ssh/authorized_keys2
or
ssh-copy-id ~/.ssh/id_rsa.pub username@example.com
# Now you can connect to the remote server with out being asked for a password.
3) ssh -l usuario server.remoto
Friday, January 30, 2009
Script to delete unwanted files
for eg to del all files ends with tilde (*~)
locate *~ > vik
a file vik is created with all such files.
Now run script
----------------
for i in `cat vik`
do
echo -e "--------------------------"
#echo -e "Delete File $i [y/n] "
#read dk
#if [ "$dk" = "y" ] ; then
rm -f $i
#echo -e "File $i deleted."
echo -e "--------------------------"
#fi
#sleep 1
done
--------------------
If u remove comments, It will ask you [y/n] every time before deleting the file.
locate *~ > vik
a file vik is created with all such files.
Now run script
----------------
for i in `cat vik`
do
echo -e "--------------------------"
#echo -e "Delete File $i [y/n] "
#read dk
#if [ "$dk" = "y" ] ; then
rm -f $i
#echo -e "File $i deleted."
echo -e "--------------------------"
#fi
#sleep 1
done
--------------------
If u remove comments, It will ask you [y/n] every time before deleting the file.
Script to delete unwanted files
for eg to del all files ends with tilde (*~)
locate *~ > vik
a file vik is created with all such files.
Now run script
----------------
for i in `cat vik`
do
echo -e "--------------------------"
#echo -e "Delete File $i [y/n] "
#read dk
#if [ "$dk" = "y" ] ; then
rm -f $i
#echo -e "File $i deleted."
echo -e "--------------------------"
#fi
#sleep 1
done
--------------------
If u remove comments, It will ask you [y/n] every time before deleting the file.
locate *~ > vik
a file vik is created with all such files.
Now run script
----------------
for i in `cat vik`
do
echo -e "--------------------------"
#echo -e "Delete File $i [y/n] "
#read dk
#if [ "$dk" = "y" ] ; then
rm -f $i
#echo -e "File $i deleted."
echo -e "--------------------------"
#fi
#sleep 1
done
--------------------
If u remove comments, It will ask you [y/n] every time before deleting the file.
script to kill a process using the PID
Script will take argument as {start|stop|restart|status}
and do with process specified [here siproxd]
One can replace siproxd as other process or take process as a argument as well.
#!/bin/bash
#
# siproxd This shell script takes care of starting and stopping
#
# chkconfig: - 13 87
# description: To start the siproxd \
# probe: true
if [ $# != 1 ]; then
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
fi
#echo -n $"Starting named: "
start()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e $"Siproxd is already running: PID" $i
else
echo -e $"Starting siproxd....."
sleep 2
/usr/local/sbin/siproxd -d 0
fi
}
stop()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
sleep 2
killall siproxd
echo -e $"Siproxd is stopped."
else
echo -e $"Siproxd was not running."
fi
}
restart()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e "Stopping siproxd."
sleep 2
killall siproxd
else
echo -e "Siproxd was not running."
fi
echo -e "Starting siproxd."
sleep 3
/usr/local/sbin/siproxd -d 0
}
status()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e "Siproxd is running: PID" $i
else
echo -e "Siproxd is not running."
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
esac
and do with process specified [here siproxd]
One can replace siproxd as other process or take process as a argument as well.
#!/bin/bash
#
# siproxd This shell script takes care of starting and stopping
#
# chkconfig: - 13 87
# description: To start the siproxd \
# probe: true
if [ $# != 1 ]; then
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
fi
#echo -n $"Starting named: "
start()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e $"Siproxd is already running: PID" $i
else
echo -e $"Starting siproxd....."
sleep 2
/usr/local/sbin/siproxd -d 0
fi
}
stop()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
sleep 2
killall siproxd
echo -e $"Siproxd is stopped."
else
echo -e $"Siproxd was not running."
fi
}
restart()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e "Stopping siproxd."
sleep 2
killall siproxd
else
echo -e "Siproxd was not running."
fi
echo -e "Starting siproxd."
sleep 3
/usr/local/sbin/siproxd -d 0
}
status()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e "Siproxd is running: PID" $i
else
echo -e "Siproxd is not running."
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
esac
script to kill a process using the PID
Script will take argument as {start|stop|restart|status}
and do with process specified [here siproxd]
One can replace siproxd as other process or take process as a argument as well.
#!/bin/bash
#
# siproxd This shell script takes care of starting and stopping
#
# chkconfig: - 13 87
# description: To start the siproxd \
# probe: true
if [ $# != 1 ]; then
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
fi
#echo -n $"Starting named: "
start()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e $"Siproxd is already running: PID" $i
else
echo -e $"Starting siproxd....."
sleep 2
/usr/local/sbin/siproxd -d 0
fi
}
stop()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
sleep 2
killall siproxd
echo -e $"Siproxd is stopped."
else
echo -e $"Siproxd was not running."
fi
}
restart()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e "Stopping siproxd."
sleep 2
killall siproxd
else
echo -e "Siproxd was not running."
fi
echo -e "Starting siproxd."
sleep 3
/usr/local/sbin/siproxd -d 0
}
status()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e "Siproxd is running: PID" $i
else
echo -e "Siproxd is not running."
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
esac
and do with process specified [here siproxd]
One can replace siproxd as other process or take process as a argument as well.
#!/bin/bash
#
# siproxd This shell script takes care of starting and stopping
#
# chkconfig: - 13 87
# description: To start the siproxd \
# probe: true
if [ $# != 1 ]; then
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
fi
#echo -n $"Starting named: "
start()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e $"Siproxd is already running: PID" $i
else
echo -e $"Starting siproxd....."
sleep 2
/usr/local/sbin/siproxd -d 0
fi
}
stop()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
sleep 2
killall siproxd
echo -e $"Siproxd is stopped."
else
echo -e $"Siproxd was not running."
fi
}
restart()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e "Stopping siproxd."
sleep 2
killall siproxd
else
echo -e "Siproxd was not running."
fi
echo -e "Starting siproxd."
sleep 3
/usr/local/sbin/siproxd -d 0
}
status()
{
inc=0
for i in `ps -A | grep siproxd | awk {'print $1'}`
do
#echo $i
inc=$(($inc+1));
done
if [ $inc != 0 ] ; then
echo -e "Siproxd is running: PID" $i
else
echo -e "Siproxd is not running."
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
esac
Taking input as password from script, passing to C code, returning to script
SCRIPT
#!/bin/sh
stty -echo;
read -p "Enter Password - " pass
echo -e
stty echo;
echo -e "#######################################"
echo -e "############# User Licence ############"
./defUser $pass
if [ $? -eq 5 ] ; then
echo -e "########################################"
echo -e "####### Licence Not Generated ##########"
exit
fi
sleep 2
echo -e "#######################################"
echo -e "######### Licence Generated ###########"
echo -e "Restart PBX"
while [ 1 ]
do
read -p "Restart now [y/n] " rst
case $rst in
y|Y) service sipxpbx stop; service sipxpbx start; exit;;
n|N) echo -e "Restart Once to Make changes effective." ;exit ;;
*) echo -e "Wrong Input!!! Please enter [y/n]";
esac
done
bash
###############################
C CODE
##############################
#include
#include
int main(int argc, char * argv[])
{
int usr, inc=0, i=0, j, k;
FILE *file;
char str[10],ch='\0';
/*
char pass[10];
printf("Enter password:-");
while (pass == "\n")
{
pass[inc]=getch();
printf("*");
inc++;
}
printf ("Password is ", pass);
*/
if ( argc != 2 ) /* argc should be 2 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf( "Wrong Password!!!\n" );
return 0;
}
if (strcmp(argv[1],"coral") == 0 )/*** Fix your password here ***/
{
printf("Enter the Number of Users :- ");
//scanf("%d", &usr);
while(ch!='\n')
{
ch=getc(stdin);
if(ch!='\n')
str[i]=ch;
i++;
}
for(j=0;j
if(!(isdigit(str[j])) )/** Cheching every char. for number **/
{
printf("%c Not a number!!!\n", str[j]);
return 5;
}
file = fopen("/etc/sipxpbx/users","w"); /* apend file (add text to a file or create a file if it does not exist.*/
for(k=0;k
{
fprintf(file,"%c", str[k]); /*writes*/
}
fclose(file); /*done!*/
printf("Defining Coral-PBX for Users :- ");
for(k=0;k
printf("%c", str[k]);
printf("\n");
//getchar(); /* pause and wait for key */
return 0;
}
else
{
printf("Wrong Password!!!\n");
return 5;
}
}
#!/bin/sh
stty -echo;
read -p "Enter Password - " pass
echo -e
stty echo;
echo -e "#######################################"
echo -e "############# User Licence ############"
./defUser $pass
if [ $? -eq 5 ] ; then
echo -e "########################################"
echo -e "####### Licence Not Generated ##########"
exit
fi
sleep 2
echo -e "#######################################"
echo -e "######### Licence Generated ###########"
echo -e "Restart PBX"
while [ 1 ]
do
read -p "Restart now [y/n] " rst
case $rst in
y|Y) service sipxpbx stop; service sipxpbx start; exit;;
n|N) echo -e "Restart Once to Make changes effective." ;exit ;;
*) echo -e "Wrong Input!!! Please enter [y/n]";
esac
done
bash
###############################
C CODE
##############################
#include
#include
int main(int argc, char * argv[])
{
int usr, inc=0, i=0, j, k;
FILE *file;
char str[10],ch='\0';
/*
char pass[10];
printf("Enter password:-");
while (pass == "\n")
{
pass[inc]=getch();
printf("*");
inc++;
}
printf ("Password is ", pass);
*/
if ( argc != 2 ) /* argc should be 2 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf( "Wrong Password!!!\n" );
return 0;
}
if (strcmp(argv[1],"coral") == 0 )/*** Fix your password here ***/
{
printf("Enter the Number of Users :- ");
//scanf("%d", &usr);
while(ch!='\n')
{
ch=getc(stdin);
if(ch!='\n')
str[i]=ch;
i++;
}
for(j=0;j
if(!(isdigit(str[j])) )/** Cheching every char. for number **/
{
printf("%c Not a number!!!\n", str[j]);
return 5;
}
file = fopen("/etc/sipxpbx/users","w"); /* apend file (add text to a file or create a file if it does not exist.*/
for(k=0;k
{
fprintf(file,"%c", str[k]); /*writes*/
}
fclose(file); /*done!*/
printf("Defining Coral-PBX for Users :- ");
for(k=0;k
printf("%c", str[k]);
printf("\n");
//getchar(); /* pause and wait for key */
return 0;
}
else
{
printf("Wrong Password!!!\n");
return 5;
}
}
Taking input as password from script, passing to C code, returning to script
SCRIPT
#!/bin/sh
stty -echo;
read -p "Enter Password - " pass
echo -e
stty echo;
echo -e "#######################################"
echo -e "############# User Licence ############"
./defUser $pass
if [ $? -eq 5 ] ; then
echo -e "########################################"
echo -e "####### Licence Not Generated ##########"
exit
fi
sleep 2
echo -e "#######################################"
echo -e "######### Licence Generated ###########"
echo -e "Restart PBX"
while [ 1 ]
do
read -p "Restart now [y/n] " rst
case $rst in
y|Y) service sipxpbx stop; service sipxpbx start; exit;;
n|N) echo -e "Restart Once to Make changes effective." ;exit ;;
*) echo -e "Wrong Input!!! Please enter [y/n]";
esac
done
bash
###############################
C CODE
##############################
#include
#include
int main(int argc, char * argv[])
{
int usr, inc=0, i=0, j, k;
FILE *file;
char str[10],ch='\0';
/*
char pass[10];
printf("Enter password:-");
while (pass == "\n")
{
pass[inc]=getch();
printf("*");
inc++;
}
printf ("Password is ", pass);
*/
if ( argc != 2 ) /* argc should be 2 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf( "Wrong Password!!!\n" );
return 0;
}
if (strcmp(argv[1],"coral") == 0 )/*** Fix your password here ***/
{
printf("Enter the Number of Users :- ");
//scanf("%d", &usr);
while(ch!='\n')
{
ch=getc(stdin);
if(ch!='\n')
str[i]=ch;
i++;
}
for(j=0;j
if(!(isdigit(str[j])) )/** Cheching every char. for number **/
{
printf("%c Not a number!!!\n", str[j]);
return 5;
}
file = fopen("/etc/sipxpbx/users","w"); /* apend file (add text to a file or create a file if it does not exist.*/
for(k=0;k
{
fprintf(file,"%c", str[k]); /*writes*/
}
fclose(file); /*done!*/
printf("Defining Coral-PBX for Users :- ");
for(k=0;k
printf("%c", str[k]);
printf("\n");
//getchar(); /* pause and wait for key */
return 0;
}
else
{
printf("Wrong Password!!!\n");
return 5;
}
}
#!/bin/sh
stty -echo;
read -p "Enter Password - " pass
echo -e
stty echo;
echo -e "#######################################"
echo -e "############# User Licence ############"
./defUser $pass
if [ $? -eq 5 ] ; then
echo -e "########################################"
echo -e "####### Licence Not Generated ##########"
exit
fi
sleep 2
echo -e "#######################################"
echo -e "######### Licence Generated ###########"
echo -e "Restart PBX"
while [ 1 ]
do
read -p "Restart now [y/n] " rst
case $rst in
y|Y) service sipxpbx stop; service sipxpbx start; exit;;
n|N) echo -e "Restart Once to Make changes effective." ;exit ;;
*) echo -e "Wrong Input!!! Please enter [y/n]";
esac
done
bash
###############################
C CODE
##############################
#include
#include
int main(int argc, char * argv[])
{
int usr, inc=0, i=0, j, k;
FILE *file;
char str[10],ch='\0';
/*
char pass[10];
printf("Enter password:-");
while (pass == "\n")
{
pass[inc]=getch();
printf("*");
inc++;
}
printf ("Password is ", pass);
*/
if ( argc != 2 ) /* argc should be 2 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf( "Wrong Password!!!\n" );
return 0;
}
if (strcmp(argv[1],"coral") == 0 )/*** Fix your password here ***/
{
printf("Enter the Number of Users :- ");
//scanf("%d", &usr);
while(ch!='\n')
{
ch=getc(stdin);
if(ch!='\n')
str[i]=ch;
i++;
}
for(j=0;j
if(!(isdigit(str[j])) )/** Cheching every char. for number **/
{
printf("%c Not a number!!!\n", str[j]);
return 5;
}
file = fopen("/etc/sipxpbx/users","w"); /* apend file (add text to a file or create a file if it does not exist.*/
for(k=0;k
{
fprintf(file,"%c", str[k]); /*writes*/
}
fclose(file); /*done!*/
printf("Defining Coral-PBX for Users :- ");
for(k=0;k
printf("%c", str[k]);
printf("\n");
//getchar(); /* pause and wait for key */
return 0;
}
else
{
printf("Wrong Password!!!\n");
return 5;
}
}
copy from remote linux machine (ssh, scp)
ssh (secure shell) - to login in remote linux machine (port 22) (service sshd )
$ssh remoteIP
enter password
copying from remote linux machine to local machine using scp (secure copy)
$ scp "root@:/path/file" /path/
[if folder use -r option with scp]
copying from local machine to remote machine
$ scp /path/file "root@:/path/"
[if folder use -r option with scp]
$ssh remoteIP
enter password
copying from remote linux machine to local machine using scp (secure copy)
$ scp "root@
[if folder use -r option with scp]
copying from local machine to remote machine
$ scp /path/file "root@
[if folder use -r option with scp]
copy from remote linux machine (ssh, scp)
ssh (secure shell) - to login in remote linux machine (port 22) (service sshd )
$ssh remoteIP
enter password
copying from remote linux machine to local machine using scp (secure copy)
$ scp "root@:/path/file" /path/
[if folder use -r option with scp]
copying from local machine to remote machine
$ scp /path/file "root@:/path/"
[if folder use -r option with scp]
$ssh remoteIP
enter password
copying from remote linux machine to local machine using scp (secure copy)
$ scp "root@
[if folder use -r option with scp]
copying from local machine to remote machine
$ scp /path/file "root@
[if folder use -r option with scp]
Memory, cpu, system info linux
Memory :--
df -h
free -m
vmstat
cat /proc/meminfo [use grep]
CPU
uptime
top -b -n 1
cat /proc.cpuinfo [use grep]
SYS INFO
dmesg
lspci
lsof /dev/disk
tcpdump 'host 192.168.4.13'
nmap 192.168.4.13
lsb_release
lsusb
netstat -ia
arp -a
arp -a 192.168.4.13
dmidecode | grep -A 5 "Base Board"
uname -a
uname -s
uname -n
uname -m
uname -p
uname -i
uname -o
uname -a
df -h
free -m
vmstat
cat /proc/meminfo [use grep]
CPU
uptime
top -b -n 1
cat /proc.cpuinfo [use grep]
SYS INFO
dmesg
lspci
lsof /dev/disk
tcpdump 'host 192.168.4.13'
nmap 192.168.4.13
lsb_release
lsusb
netstat -ia
arp -a
arp -a 192.168.4.13
dmidecode | grep -A 5 "Base Board"
uname -a
uname -s
uname -n
uname -m
uname -p
uname -i
uname -o
uname -a
Memory, cpu, system info linux
Memory :--
df -h
free -m
vmstat
cat /proc/meminfo [use grep]
CPU
uptime
top -b -n 1
cat /proc.cpuinfo [use grep]
SYS INFO
dmesg
lspci
lsof /dev/disk
tcpdump 'host 192.168.4.13'
nmap 192.168.4.13
lsb_release
lsusb
netstat -ia
arp -a
arp -a 192.168.4.13
dmidecode | grep -A 5 "Base Board"
uname -a
uname -s
uname -n
uname -m
uname -p
uname -i
uname -o
uname -a
df -h
free -m
vmstat
cat /proc/meminfo [use grep]
CPU
uptime
top -b -n 1
cat /proc.cpuinfo [use grep]
SYS INFO
dmesg
lspci
lsof /dev/disk
tcpdump 'host 192.168.4.13'
nmap 192.168.4.13
lsb_release
lsusb
netstat -ia
arp -a
arp -a 192.168.4.13
dmidecode | grep -A 5 "Base Board"
uname -a
uname -s
uname -n
uname -m
uname -p
uname -i
uname -o
uname -a
Count lines of all files in a folder
This will count lines of every file in the folder, and give aggregate number of lines as well
find /path/to/dir -type f -name '*' | xargs wc -l
[Specifying the extension of file ]
find /path/to/dir -type f -name '*.c' | xargs wc -l
[This will lists the files in that folder with .c extension]
find /path/to/dir -type f -name '*.c'
find /path/to/dir -type f -name '*' | xargs wc -l
[Specifying the extension of file ]
find /path/to/dir -type f -name '*.c' | xargs wc -l
[This will lists the files in that folder with .c extension]
find /path/to/dir -type f -name '*.c'
Count lines of all files in a folder
This will count lines of every file in the folder, and give aggregate number of lines as well
find /path/to/dir -type f -name '*' | xargs wc -l
[Specifying the extension of file ]
find /path/to/dir -type f -name '*.c' | xargs wc -l
[This will lists the files in that folder with .c extension]
find /path/to/dir -type f -name '*.c'
find /path/to/dir -type f -name '*' | xargs wc -l
[Specifying the extension of file ]
find /path/to/dir -type f -name '*.c' | xargs wc -l
[This will lists the files in that folder with .c extension]
find /path/to/dir -type f -name '*.c'
Echo output in different colors
echo -e "\033[31m Hello World"
# Red color
echo -e "\033[32m Hello World"
# Green color
echo -e "\033[33m Hello World"
echo -e "\033[34m Hello World"
echo -e "\033[35m Hello World"
echo -e "\033[36m Hello World"
echo -e "\033[41m Hello World"
echo -e "\033[42m Hello World"
echo -e "\033[43m Hello World"
echo -e "\033[44m Hello World"
echo -e "\033[45m Hello World"
echo -e "\033[46m Hello World"
This one is for normal.
echo -e "\033[0m Hello World"
# Red color
echo -e "\033[32m Hello World"
# Green color
echo -e "\033[33m Hello World"
echo -e "\033[34m Hello World"
echo -e "\033[35m Hello World"
echo -e "\033[36m Hello World"
echo -e "\033[41m Hello World"
echo -e "\033[42m Hello World"
echo -e "\033[43m Hello World"
echo -e "\033[44m Hello World"
echo -e "\033[45m Hello World"
echo -e "\033[46m Hello World"
This one is for normal.
echo -e "\033[0m Hello World"
Echo output in different colors
echo -e "\033[31m Hello World"
# Red color
echo -e "\033[32m Hello World"
# Green color
echo -e "\033[33m Hello World"
echo -e "\033[34m Hello World"
echo -e "\033[35m Hello World"
echo -e "\033[36m Hello World"
echo -e "\033[41m Hello World"
echo -e "\033[42m Hello World"
echo -e "\033[43m Hello World"
echo -e "\033[44m Hello World"
echo -e "\033[45m Hello World"
echo -e "\033[46m Hello World"
This one is for normal.
echo -e "\033[0m Hello World"
# Red color
echo -e "\033[32m Hello World"
# Green color
echo -e "\033[33m Hello World"
echo -e "\033[34m Hello World"
echo -e "\033[35m Hello World"
echo -e "\033[36m Hello World"
echo -e "\033[41m Hello World"
echo -e "\033[42m Hello World"
echo -e "\033[43m Hello World"
echo -e "\033[44m Hello World"
echo -e "\033[45m Hello World"
echo -e "\033[46m Hello World"
This one is for normal.
echo -e "\033[0m Hello World"
Thursday, January 29, 2009
List of all users and gropus
[groups]
awk -F: '{if ($3>=500 && $3<=1000) print $1}' /etc/group
awk -F: '{if ($3>=500 && $3<=1000) print}' /etc/group | cut -d: -f1
cat /etc/group | cut -d: -f1
[users]
cat /etc/passwd | cut -d: -f1
awk -F: '{if ($3>=500 && $3<=1000) print $1}' /etc/passwd
awk -F: '{if ($3>=500 && $3<=1000) print}' /etc/passwd | cut -d: -f1
cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]" | grep "/home" | cut -d: -f1
cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]"
awk -F: '{if ($3>=500 && $3<=1000) print $1}' /etc/group
awk -F: '{if ($3>=500 && $3<=1000) print}' /etc/group | cut -d: -f1
cat /etc/group | cut -d: -f1
[users]
cat /etc/passwd | cut -d: -f1
awk -F: '{if ($3>=500 && $3<=1000) print $1}' /etc/passwd
awk -F: '{if ($3>=500 && $3<=1000) print}' /etc/passwd | cut -d: -f1
cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]" | grep "/home" | cut -d: -f1
cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]"
List of all users and gropus
[groups]
awk -F: '{if ($3>=500 && $3<=1000) print $1}' /etc/group
awk -F: '{if ($3>=500 && $3<=1000) print}' /etc/group | cut -d: -f1
cat /etc/group | cut -d: -f1
[users]
cat /etc/passwd | cut -d: -f1
awk -F: '{if ($3>=500 && $3<=1000) print $1}' /etc/passwd
awk -F: '{if ($3>=500 && $3<=1000) print}' /etc/passwd | cut -d: -f1
cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]" | grep "/home" | cut -d: -f1
cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]"
awk -F: '{if ($3>=500 && $3<=1000) print $1}' /etc/group
awk -F: '{if ($3>=500 && $3<=1000) print}' /etc/group | cut -d: -f1
cat /etc/group | cut -d: -f1
[users]
cat /etc/passwd | cut -d: -f1
awk -F: '{if ($3>=500 && $3<=1000) print $1}' /etc/passwd
awk -F: '{if ($3>=500 && $3<=1000) print}' /etc/passwd | cut -d: -f1
cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]" | grep "/home" | cut -d: -f1
cat /etc/passwd | cut -d: -f 1,3,6 | grep "[5-9][0-9][0-9]"
Find symbolic link in a dir
With single command
find path_to_dir -lname "*"
OR
ls -l | grep ^l
OR COUNT
ls -l | grep ^l | wc -l
SCRIPT
#echo -n "Enter file name : "
#read file
echo -n "Enter dir name/path : "
read dir1
echo "***********************"
echo "Files are symbolic link"
find $dir1 -lname '*'
echo "***********************"
for file1 in `ls $dir1`
do
# find out if file has write permission or not
#[ -w $file1 ] && W="Write = yes" || W="Write = No"
# find out if file has excute permission or not
#[ -x $file1 ] && X="Execute = yes" || X="Execute = No"
# find out if file has read permission or not
#[ -r $file1 ] && R="Read = yes" || R="Read = No"
#echo "$file permissions"
#echo "$W"
#echo "$R"
#echo
dr="$dir1/$file1"
#echo $dr
if [ -L $dr ] ; then
sym="Its a Symbolik link"
else
sym="Its a not Symbolic link."
fi
echo -e $file1
echo $sym
done
find path_to_dir -lname "*"
OR
ls -l | grep ^l
OR COUNT
ls -l | grep ^l | wc -l
SCRIPT
#echo -n "Enter file name : "
#read file
echo -n "Enter dir name/path : "
read dir1
echo "***********************"
echo "Files are symbolic link"
find $dir1 -lname '*'
echo "***********************"
for file1 in `ls $dir1`
do
# find out if file has write permission or not
#[ -w $file1 ] && W="Write = yes" || W="Write = No"
# find out if file has excute permission or not
#[ -x $file1 ] && X="Execute = yes" || X="Execute = No"
# find out if file has read permission or not
#[ -r $file1 ] && R="Read = yes" || R="Read = No"
#echo "$file permissions"
#echo "$W"
#echo "$R"
#echo
dr="$dir1/$file1"
#echo $dr
if [ -L $dr ] ; then
sym="Its a Symbolik link"
else
sym="Its a not Symbolic link."
fi
echo -e $file1
echo $sym
done
Find symbolic link in a dir
With single command
find path_to_dir -lname "*"
OR
ls -l | grep ^l
OR COUNT
ls -l | grep ^l | wc -l
SCRIPT
#echo -n "Enter file name : "
#read file
echo -n "Enter dir name/path : "
read dir1
echo "***********************"
echo "Files are symbolic link"
find $dir1 -lname '*'
echo "***********************"
for file1 in `ls $dir1`
do
# find out if file has write permission or not
#[ -w $file1 ] && W="Write = yes" || W="Write = No"
# find out if file has excute permission or not
#[ -x $file1 ] && X="Execute = yes" || X="Execute = No"
# find out if file has read permission or not
#[ -r $file1 ] && R="Read = yes" || R="Read = No"
#echo "$file permissions"
#echo "$W"
#echo "$R"
#echo
dr="$dir1/$file1"
#echo $dr
if [ -L $dr ] ; then
sym="Its a Symbolik link"
else
sym="Its a not Symbolic link."
fi
echo -e $file1
echo $sym
done
find path_to_dir -lname "*"
OR
ls -l | grep ^l
OR COUNT
ls -l | grep ^l | wc -l
SCRIPT
#echo -n "Enter file name : "
#read file
echo -n "Enter dir name/path : "
read dir1
echo "***********************"
echo "Files are symbolic link"
find $dir1 -lname '*'
echo "***********************"
for file1 in `ls $dir1`
do
# find out if file has write permission or not
#[ -w $file1 ] && W="Write = yes" || W="Write = No"
# find out if file has excute permission or not
#[ -x $file1 ] && X="Execute = yes" || X="Execute = No"
# find out if file has read permission or not
#[ -r $file1 ] && R="Read = yes" || R="Read = No"
#echo "$file permissions"
#echo "$W"
#echo "$R"
#echo
dr="$dir1/$file1"
#echo $dr
if [ -L $dr ] ; then
sym="Its a Symbolik link"
else
sym="Its a not Symbolic link."
fi
echo -e $file1
echo $sym
done
एक्स्त्रक्टिंग IP address from ifconfig
ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | cut -d":" -f2
ifconfig eth0 | sed -n 's/.*inet addr:\([0-9.]*\).*/\1/p'
command get_def_addr will return ip address
ifconfig eth0 | sed -n 's/.*inet addr:\([0-9.]*\).*/\1/p'
command get_def_addr will return ip address
एक्स्त्रक्टिंग IP address from ifconfig
ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | cut -d":" -f2
ifconfig eth0 | sed -n 's/.*inet addr:\([0-9.]*\).*/\1/p'
command get_def_addr will return ip address
ifconfig eth0 | sed -n 's/.*inet addr:\([0-9.]*\).*/\1/p'
command get_def_addr will return ip address
Scheduling in linux using the crontab
When you need to do something i.e mail, run a script, backup etc. automatically after some specific time, i.e once a day. once a week, after every hour.
crontab command is helpful for such.
crontab -e Edit your crontab file, or create one if it doesn't already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
min hour day month dyaofweek
e.g
55 23 * * * sh /etc/sipx_mapp/cdrscript.sh
50 23 * * * do something
01 * * * * do something [ or every hour]
Means every day at 23:55 (11:55 at night) script will run
14 2 29 8 5 ./skynet
This will launch at 2:14 AM, on August 29 if it is a Friday.
Activation parameters:
@reboot = run at boot and reboot only
@yearly = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@annually = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@monthly = run at midnight on the first day of each month (equiv to 0 0 1 * *)
@weekly = run at midnight each Sunday (equiv to 0 0 * * 0)
@daily = run at midnight each day (equiv to 0 0 * * *)
@ midnight = run at midnight each day (equiv to 0 0 * * *)
@ hourly = run on the first second of every hour (equiv to 0 * * * *)
crontab command is helpful for such.
crontab -e Edit your crontab file, or create one if it doesn't already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
# min(0-59) hours(0-23) day(1-31) month(1-12) dow(0-6) command
34 2 * * * sh /root/backup.sh
min hour day month dyaofweek
e.g
55 23 * * * sh /etc/sipx_mapp/cdrscript.sh
50 23 * * * do something
01 * * * * do something [ or every hour]
Means every day at 23:55 (11:55 at night) script will run
14 2 29 8 5 ./skynet
This will launch at 2:14 AM, on August 29 if it is a Friday.
Activation parameters:
@reboot = run at boot and reboot only
@yearly = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@annually = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@monthly = run at midnight on the first day of each month (equiv to 0 0 1 * *)
@weekly = run at midnight each Sunday (equiv to 0 0 * * 0)
@daily = run at midnight each day (equiv to 0 0 * * *)
@ midnight = run at midnight each day (equiv to 0 0 * * *)
@ hourly = run on the first second of every hour (equiv to 0 * * * *)
Scheduling in linux using the crontab
When you need to do something i.e mail, run a script, backup etc. automatically after some specific time, i.e once a day. once a week, after every hour.
crontab command is helpful for such.
crontab -e Edit your crontab file, or create one if it doesn't already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
min hour day month dyaofweek
e.g
55 23 * * * sh /etc/sipx_mapp/cdrscript.sh
50 23 * * * do something
01 * * * * do something [ or every hour]
Means every day at 23:55 (11:55 at night) script will run
14 2 29 8 5 ./skynet
This will launch at 2:14 AM, on August 29 if it is a Friday.
Activation parameters:
@reboot = run at boot and reboot only
@yearly = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@annually = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@monthly = run at midnight on the first day of each month (equiv to 0 0 1 * *)
@weekly = run at midnight each Sunday (equiv to 0 0 * * 0)
@daily = run at midnight each day (equiv to 0 0 * * *)
@ midnight = run at midnight each day (equiv to 0 0 * * *)
@ hourly = run on the first second of every hour (equiv to 0 * * * *)
crontab command is helpful for such.
crontab -e Edit your crontab file, or create one if it doesn't already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
# min(0-59) hours(0-23) day(1-31) month(1-12) dow(0-6) command
34 2 * * * sh /root/backup.sh
min hour day month dyaofweek
e.g
55 23 * * * sh /etc/sipx_mapp/cdrscript.sh
50 23 * * * do something
01 * * * * do something [ or every hour]
Means every day at 23:55 (11:55 at night) script will run
14 2 29 8 5 ./skynet
This will launch at 2:14 AM, on August 29 if it is a Friday.
Activation parameters:
@reboot = run at boot and reboot only
@yearly = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@annually = run at midnight Jan 1 each year (equiv to 0 0 1 1 *)
@monthly = run at midnight on the first day of each month (equiv to 0 0 1 * *)
@weekly = run at midnight each Sunday (equiv to 0 0 * * 0)
@daily = run at midnight each day (equiv to 0 0 * * *)
@ midnight = run at midnight each day (equiv to 0 0 * * *)
@ hourly = run on the first second of every hour (equiv to 0 * * * *)
Changing / Breaking root password in Linux even when grub is password protected
Boot from CD
It will take you
boot:
type 'linux rescue' at this command prompt and enter
It will take you to some interface with some questions , answer them properly .
The system will go to temporary command prompt.Then issue the following commands
now in this file you can see a line beginning with the word 'password' remove this line and save the file.
It will take you
boot:
type 'linux rescue' at this command prompt and enter
It will take you to some interface with some questions , answer them properly .
The system will go to temporary command prompt.Then issue the following commands
[bash$] chroot /mnt/sysimage [Enter]
[bash$] cd /boot/grub [Enter]
[bash$] vi menu.lst [Enter]
now in this file you can see a line beginning with the word 'password' remove this line and save the file.
[bash$]exit
[bash$]exit
Remove the CD.
Now system will be rebooted and you can see the grub without a password.
Changing / Breaking root password in Linux even when grub is password protected
Boot from CD
It will take you
boot:
type 'linux rescue' at this command prompt and enter
It will take you to some interface with some questions , answer them properly .
The system will go to temporary command prompt.Then issue the following commands
now in this file you can see a line beginning with the word 'password' remove this line and save the file.
It will take you
boot:
type 'linux rescue' at this command prompt and enter
It will take you to some interface with some questions , answer them properly .
The system will go to temporary command prompt.Then issue the following commands
[bash$] chroot /mnt/sysimage [Enter]
[bash$] cd /boot/grub [Enter]
[bash$] vi menu.lst [Enter]
now in this file you can see a line beginning with the word 'password' remove this line and save the file.
[bash$]exit
[bash$]exit
Remove the CD.
Now system will be rebooted and you can see the grub without a password.
Giving grub a password
[root@vikas ~]# grub-md5-crypt
Password:
Retype password:
$1$0momt$iyfphL4LSrQse/JHNI471/
[root@vikas ~]#
Now add password in the /etc/grub.conf
password -md5 $1$0momt$iyfphL4LSrQse/JHNI471/
Now every time you login first you need to give the grub password as well, whether you you login as a single user or a normal boot.
Password:
Retype password:
$1$0momt$iyfphL4LSrQse/JHNI471/
[root@vikas ~]#
Now add password in the /etc/grub.conf
password -md5 $1$0momt$iyfphL4LSrQse/JHNI471/
Now every time you login first you need to give the grub password as well, whether you you login as a single user or a normal boot.
Giving grub a password
[root@vikas ~]# grub-md5-crypt
Password:
Retype password:
$1$0momt$iyfphL4LSrQse/JHNI471/
[root@vikas ~]#
Now add password in the /etc/grub.conf
password -md5 $1$0momt$iyfphL4LSrQse/JHNI471/
Now every time you login first you need to give the grub password as well, whether you you login as a single user or a normal boot.
Password:
Retype password:
$1$0momt$iyfphL4LSrQse/JHNI471/
[root@vikas ~]#
Now add password in the /etc/grub.conf
password -md5 $1$0momt$iyfphL4LSrQse/JHNI471/
Now every time you login first you need to give the grub password as well, whether you you login as a single user or a normal boot.
Break root password in the linux
METHOD 1 [When you are already login]
Open file /etc/passed
Edit line root:x:0:0:Vikas:/root:/bin/bash
to root::0:0:Vikas:/root:/bin/bash
Edit root line, just delete the char. x.
Save file.
When you boot next time, user root will not ask you the PASSWORD.
METHOD 2 [Change root password before login, even of you do not know the root password]
1) At the grub screen press 'e' on linux
2) Goto line which contains the word 'kernel' and press 'e'
A screen will be displayed with some line.
3) Go to end of that line and write 'linux single' or goto end of line give one space or just type '1'
4) Then press 'esc' twice to come back on grub screen and press 'b' to reboot the system
5) Now wait for the prompt u get, after getting the prompt write command to change the passwd i.e:
passwd root
METHOD 3 [With boot CD]
1. Boot the computer with Linux Installation CD.
2. Enter into Linux Rescue mode by entering the following command in boot screen.
boot: linux rescue
3. When the sh prompt is reached, enter the following commands to change root password.
#chroot /mnt/sysimage
#passwd
The above steps will prompt you to enter your new password.
Open file /etc/passed
Edit line root:x:0:0:Vikas:/root:/bin/bash
to root::0:0:Vikas:/root:/bin/bash
Edit root line, just delete the char. x.
Save file.
When you boot next time, user root will not ask you the PASSWORD.
METHOD 2 [Change root password before login, even of you do not know the root password]
1) At the grub screen press 'e' on linux
2) Goto line which contains the word 'kernel' and press 'e'
A screen will be displayed with some line.
3) Go to end of that line and write 'linux single' or goto end of line give one space or just type '1'
4) Then press 'esc' twice to come back on grub screen and press 'b' to reboot the system
5) Now wait for the prompt u get, after getting the prompt write command to change the passwd i.e:
passwd root
METHOD 3 [With boot CD]
1. Boot the computer with Linux Installation CD.
2. Enter into Linux Rescue mode by entering the following command in boot screen.
boot: linux rescue
3. When the sh prompt is reached, enter the following commands to change root password.
#chroot /mnt/sysimage
#passwd
The above steps will prompt you to enter your new password.
Break root password in the linux
METHOD 1 [When you are already login]
Open file /etc/passed
Edit line root:x:0:0:Vikas:/root:/bin/bash
to root::0:0:Vikas:/root:/bin/bash
Edit root line, just delete the char. x.
Save file.
When you boot next time, user root will not ask you the PASSWORD.
METHOD 2 [Change root password before login, even of you do not know the root password]
1) At the grub screen press 'e' on linux
2) Goto line which contains the word 'kernel' and press 'e'
A screen will be displayed with some line.
3) Go to end of that line and write 'linux single' or goto end of line give one space or just type '1'
4) Then press 'esc' twice to come back on grub screen and press 'b' to reboot the system
5) Now wait for the prompt u get, after getting the prompt write command to change the passwd i.e:
passwd root
METHOD 3 [With boot CD]
1. Boot the computer with Linux Installation CD.
2. Enter into Linux Rescue mode by entering the following command in boot screen.
boot: linux rescue
3. When the sh prompt is reached, enter the following commands to change root password.
#chroot /mnt/sysimage
#passwd
The above steps will prompt you to enter your new password.
Open file /etc/passed
Edit line root:x:0:0:Vikas:/root:/bin/bash
to root::0:0:Vikas:/root:/bin/bash
Edit root line, just delete the char. x.
Save file.
When you boot next time, user root will not ask you the PASSWORD.
METHOD 2 [Change root password before login, even of you do not know the root password]
1) At the grub screen press 'e' on linux
2) Goto line which contains the word 'kernel' and press 'e'
A screen will be displayed with some line.
3) Go to end of that line and write 'linux single' or goto end of line give one space or just type '1'
4) Then press 'esc' twice to come back on grub screen and press 'b' to reboot the system
5) Now wait for the prompt u get, after getting the prompt write command to change the passwd i.e:
passwd root
METHOD 3 [With boot CD]
1. Boot the computer with Linux Installation CD.
2. Enter into Linux Rescue mode by entering the following command in boot screen.
boot: linux rescue
3. When the sh prompt is reached, enter the following commands to change root password.
#chroot /mnt/sysimage
#passwd
The above steps will prompt you to enter your new password.
Wednesday, January 28, 2009
How to install Internet Explorer on Linux
cabextract and wine must be installed on you linux pc.
One can use yum for them.
Download ies4linux-latest.tar.gz
wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
Extract it
tar zxvf ies4linux-latest.tar.gz
change dir
cd ies4linux-*
run the script
./ies4linux
Now you will get a ie6 script may be in /root/bin/ie6
From terminal run
$ ie6
this will start the IE
A good link
http://www.tatanka.com.br/ies4linux/page/Installation
How to install Internet Explorer on Linux
cabextract and wine must be installed on you linux pc.
One can use yum for them.
Download ies4linux-latest.tar.gz
wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
Extract it
tar zxvf ies4linux-latest.tar.gz
change dir
cd ies4linux-*
run the script
./ies4linux
Now you will get a ie6 script may be in /root/bin/ie6
From terminal run
$ ie6
this will start the IE
A good link
http://www.tatanka.com.br/ies4linux/page/Installation
Using date in various ways from terminal
Date can used as a part of file name, helpful in logs and backups
date -d '1 month ago' -I [ show 1 month ago date ]
2008-12-28
date -d '1 year ago' -I [ show 1 year ago date ]
2008-01-28
date -d '1 day ago' -I [ show 1 day ago date ]
2009-01-27
date -d -I
Wed Jan 28 14:30:00 IST 2009
date -I
2009-01-28
date +%Y%m%d
20090128
date +%Y/%m/%d
2009/01/28
date --date='25 Dec' +%A
Friday
date -d fri
Fri Jan 30 00:00:00 IST 2009
date -d "tomorrow" +%d
29
date -d "tomorrow"
Thu Jan 29 12:43:07 IST 2009
date -d '2 day' -I [ showing date after two days ]
2009-01-30
USEFUL LITERALS
%% a literal %
%a locale's abbreviated weekday name (e.g., Sun)
%A locale's full weekday name (e.g., Sunday)
%b locale's abbreviated month name (e.g., Jan)
%B locale's full month name (e.g., January)
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 21)
%d day of month (e.g, 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale's equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale's 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
%t a tab
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
%w day of week (0..6); 0 is Sunday
%W week number of year, with Monday as first day of week (00..53)
%x locale's date representation (e.g., 12/31/99)
%X locale's time representation (e.g., 23:13:48)
%y last two digits of year (00..99)
%Y year
%z +hhmm numeric timezone (e.g., -0400)
%:z +hh:mm numeric timezone (e.g., -04:00)
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
%Z alphabetic time zone abbreviation (e.g., EDT)
date -d '1 month ago' -I [ show 1 month ago date ]
2008-12-28
date -d '1 year ago' -I [ show 1 year ago date ]
2008-01-28
date -d '1 day ago' -I [ show 1 day ago date ]
2009-01-27
date -d -I
Wed Jan 28 14:30:00 IST 2009
date -I
2009-01-28
date +%Y%m%d
20090128
date +%Y/%m/%d
2009/01/28
date --date='25 Dec' +%A
Friday
date -d fri
Fri Jan 30 00:00:00 IST 2009
date -d "tomorrow" +%d
29
date -d "tomorrow"
Thu Jan 29 12:43:07 IST 2009
date -d '2 day' -I [ showing date after two days ]
2009-01-30
USEFUL LITERALS
%% a literal %
%a locale's abbreviated weekday name (e.g., Sun)
%A locale's full weekday name (e.g., Sunday)
%b locale's abbreviated month name (e.g., Jan)
%B locale's full month name (e.g., January)
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 21)
%d day of month (e.g, 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale's equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale's 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
%t a tab
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
%w day of week (0..6); 0 is Sunday
%W week number of year, with Monday as first day of week (00..53)
%x locale's date representation (e.g., 12/31/99)
%X locale's time representation (e.g., 23:13:48)
%y last two digits of year (00..99)
%Y year
%z +hhmm numeric timezone (e.g., -0400)
%:z +hh:mm numeric timezone (e.g., -04:00)
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
%Z alphabetic time zone abbreviation (e.g., EDT)
Using date in various ways from terminal
Date can used as a part of file name, helpful in logs and backups
date -d '1 month ago' -I [ show 1 month ago date ]
2008-12-28
date -d '1 year ago' -I [ show 1 year ago date ]
2008-01-28
date -d '1 day ago' -I [ show 1 day ago date ]
2009-01-27
date -d -I
Wed Jan 28 14:30:00 IST 2009
date -I
2009-01-28
date +%Y%m%d
20090128
date +%Y/%m/%d
2009/01/28
date --date='25 Dec' +%A
Friday
date -d fri
Fri Jan 30 00:00:00 IST 2009
date -d "tomorrow" +%d
29
date -d "tomorrow"
Thu Jan 29 12:43:07 IST 2009
date -d '2 day' -I [ showing date after two days ]
2009-01-30
USEFUL LITERALS
%% a literal %
%a locale's abbreviated weekday name (e.g., Sun)
%A locale's full weekday name (e.g., Sunday)
%b locale's abbreviated month name (e.g., Jan)
%B locale's full month name (e.g., January)
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 21)
%d day of month (e.g, 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale's equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale's 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
%t a tab
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
%w day of week (0..6); 0 is Sunday
%W week number of year, with Monday as first day of week (00..53)
%x locale's date representation (e.g., 12/31/99)
%X locale's time representation (e.g., 23:13:48)
%y last two digits of year (00..99)
%Y year
%z +hhmm numeric timezone (e.g., -0400)
%:z +hh:mm numeric timezone (e.g., -04:00)
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
%Z alphabetic time zone abbreviation (e.g., EDT)
date -d '1 month ago' -I [ show 1 month ago date ]
2008-12-28
date -d '1 year ago' -I [ show 1 year ago date ]
2008-01-28
date -d '1 day ago' -I [ show 1 day ago date ]
2009-01-27
date -d -I
Wed Jan 28 14:30:00 IST 2009
date -I
2009-01-28
date +%Y%m%d
20090128
date +%Y/%m/%d
2009/01/28
date --date='25 Dec' +%A
Friday
date -d fri
Fri Jan 30 00:00:00 IST 2009
date -d "tomorrow" +%d
29
date -d "tomorrow"
Thu Jan 29 12:43:07 IST 2009
date -d '2 day' -I [ showing date after two days ]
2009-01-30
USEFUL LITERALS
%% a literal %
%a locale's abbreviated weekday name (e.g., Sun)
%A locale's full weekday name (e.g., Sunday)
%b locale's abbreviated month name (e.g., Jan)
%B locale's full month name (e.g., January)
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 21)
%d day of month (e.g, 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale's equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale's 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
%t a tab
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%U week number of year, with Sunday as first day of week (00..53)
%V ISO week number, with Monday as first day of week (01..53)
%w day of week (0..6); 0 is Sunday
%W week number of year, with Monday as first day of week (00..53)
%x locale's date representation (e.g., 12/31/99)
%X locale's time representation (e.g., 23:13:48)
%y last two digits of year (00..99)
%Y year
%z +hhmm numeric timezone (e.g., -0400)
%:z +hh:mm numeric timezone (e.g., -04:00)
%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)
%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)
%Z alphabetic time zone abbreviation (e.g., EDT)
Files changed in a folder
How to know which files has been changed in last 30 mins, in a folder?
find /path/of/folder -cmin 30 -print
This will find files changed in last 30 mins in the specified folder.
find /path/of/folder -cmin 30 -print
This will find files changed in last 30 mins in the specified folder.
Files changed in a folder
How to know which files has been changed in last 30 mins, in a folder?
find /path/of/folder -cmin 30 -print
This will find files changed in last 30 mins in the specified folder.
find /path/of/folder -cmin 30 -print
This will find files changed in last 30 mins in the specified folder.
Tuesday, January 27, 2009
creating a service, add to chkconfig in fedora
Save your script in
/etc/init.d/ with exe permissions
statement contain the runlevels to enable the script at, the value to use after the “S” in the start scripts, and the value to use after the “K” in the kill scripts
Lets say file name is vikas
Now
ln -s /etc/init.d/vikas /etc/rc1.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc2.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc3.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc4.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc4.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc5.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc5.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc6.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc6.d/k97vikas
make the symbolic links in the appropriate run levels i.e rc(1-6). dir as above starting from S and K
Add as service
chkconfig --add vikas
Example file
-------------------------------------------------
#!/bin/bash
#
# vikas This shell script takes care of starting and stopping
# named (BIND DNS server).
#
# chkconfig: - 13 87
# description: vikas to start the siproxd \
# probe: true
#echo "************************Vikas Sharma*****************************"
start()
{
touch /root/Desktop/vikas_from_startup_script
echo -e "Started...."
}
stop()
{
touch /root/Desktop/vikas_from_startup_script
echo -e "Stoped..."
}
restart()
{
echo -e "Restarting..."
rm -f /root/Desktop/vikas_from_startup_script
sleep 5
touch /root/Desktop/vikas_from_startup_script
echo -e "Restarted..."
}
status()
{
echo -e "Running..."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
esac
--------------------------------------------------
Description is must.
On on startup
chkconfig vikas on
/etc/init.d/ with exe permissions
statement contain the runlevels to enable the script at, the value to use after the “S” in the start scripts, and the value to use after the “K” in the kill scripts
Lets say file name is vikas
Now
ln -s /etc/init.d/vikas /etc/rc1.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc2.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc3.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc4.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc4.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc5.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc5.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc6.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc6.d/k97vikas
make the symbolic links in the appropriate run levels i.e rc(1-6). dir as above starting from S and K
Add as service
chkconfig --add vikas
Example file
-------------------------------------------------
#!/bin/bash
#
# vikas This shell script takes care of starting and stopping
# named (BIND DNS server).
#
# chkconfig: - 13 87
# description: vikas to start the siproxd \
# probe: true
#echo "************************Vikas Sharma*****************************"
start()
{
touch /root/Desktop/vikas_from_startup_script
echo -e "Started...."
}
stop()
{
touch /root/Desktop/vikas_from_startup_script
echo -e "Stoped..."
}
restart()
{
echo -e "Restarting..."
rm -f /root/Desktop/vikas_from_startup_script
sleep 5
touch /root/Desktop/vikas_from_startup_script
echo -e "Restarted..."
}
status()
{
echo -e "Running..."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
esac
--------------------------------------------------
Description is must.
On on startup
chkconfig vikas on
creating a service, add to chkconfig in fedora
Save your script in
/etc/init.d/ with exe permissions
statement contain the runlevels to enable the script at, the value to use after the “S” in the start scripts, and the value to use after the “K” in the kill scripts
Lets say file name is vikas
Now
ln -s /etc/init.d/vikas /etc/rc1.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc2.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc3.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc4.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc4.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc5.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc5.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc6.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc6.d/k97vikas
make the symbolic links in the appropriate run levels i.e rc(1-6). dir as above starting from S and K
Add as service
chkconfig --add vikas
Example file
-------------------------------------------------
#!/bin/bash
#
# vikas This shell script takes care of starting and stopping
# named (BIND DNS server).
#
# chkconfig: - 13 87
# description: vikas to start the siproxd \
# probe: true
#echo "************************Vikas Sharma*****************************"
start()
{
touch /root/Desktop/vikas_from_startup_script
echo -e "Started...."
}
stop()
{
touch /root/Desktop/vikas_from_startup_script
echo -e "Stoped..."
}
restart()
{
echo -e "Restarting..."
rm -f /root/Desktop/vikas_from_startup_script
sleep 5
touch /root/Desktop/vikas_from_startup_script
echo -e "Restarted..."
}
status()
{
echo -e "Running..."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
esac
--------------------------------------------------
Description is must.
On on startup
chkconfig vikas on
/etc/init.d/ with exe permissions
statement contain the runlevels to enable the script at, the value to use after the “S” in the start scripts, and the value to use after the “K” in the kill scripts
Lets say file name is vikas
Now
ln -s /etc/init.d/vikas /etc/rc1.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc2.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc3.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc4.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc4.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc5.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc5.d/k97vikas
ln -s /etc/init.d/vikas /etc/rc6.d/S97vikas
ln -s /etc/init.d/vikas /etc/rc6.d/k97vikas
make the symbolic links in the appropriate run levels i.e rc(1-6). dir as above starting from S and K
Add as service
chkconfig --add vikas
Example file
-------------------------------------------------
#!/bin/bash
#
# vikas This shell script takes care of starting and stopping
# named (BIND DNS server).
#
# chkconfig: - 13 87
# description: vikas to start the siproxd \
# probe: true
#echo "************************Vikas Sharma*****************************"
start()
{
touch /root/Desktop/vikas_from_startup_script
echo -e "Started...."
}
stop()
{
touch /root/Desktop/vikas_from_startup_script
echo -e "Stoped..."
}
restart()
{
echo -e "Restarting..."
rm -f /root/Desktop/vikas_from_startup_script
sleep 5
touch /root/Desktop/vikas_from_startup_script
echo -e "Restarted..."
}
status()
{
echo -e "Running..."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 3
esac
--------------------------------------------------
Description is must.
On on startup
chkconfig vikas on
Network setting related files and folder - How to change IP in linux
Host Name
Edit file /etc/sysconfig/network
[root@vikas ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=vikas.coralsip.com
[root@vikas ~]#
IP
Edit file /etc/sysconfig/network-scripts/ifcfg-eth(n)
[root@vikas network-scripts]# cat ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:40:F4:C1:F0:BB
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.4.13
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
BROADCAST=192.168.4.255
NETWORK=192.168.4.0
GATEWAY=192.168.4.254
[root@vikas network-scripts]#
OR use the cmd and edit the host name, ip and dns
neat
system-config-network or
system-config-network-tui or
system-config-network-gui
Edit file /etc/sysconfig/network
[root@vikas ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=vikas.coralsip.com
[root@vikas ~]#
IP
Edit file /etc/sysconfig/network-scripts/ifcfg-eth(n)
[root@vikas network-scripts]# cat ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:40:F4:C1:F0:BB
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.4.13
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
BROADCAST=192.168.4.255
NETWORK=192.168.4.0
GATEWAY=192.168.4.254
[root@vikas network-scripts]#
OR use the cmd and edit the host name, ip and dns
neat
system-config-network or
system-config-network-tui or
system-config-network-gui
Network setting related files and folder - How to change IP in linux
Host Name
Edit file /etc/sysconfig/network
[root@vikas ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=vikas.coralsip.com
[root@vikas ~]#
IP
Edit file /etc/sysconfig/network-scripts/ifcfg-eth(n)
[root@vikas network-scripts]# cat ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:40:F4:C1:F0:BB
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.4.13
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
BROADCAST=192.168.4.255
NETWORK=192.168.4.0
GATEWAY=192.168.4.254
[root@vikas network-scripts]#
OR use the cmd and edit the host name, ip and dns
neat
system-config-network or
system-config-network-tui or
system-config-network-gui
Edit file /etc/sysconfig/network
[root@vikas ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=vikas.coralsip.com
[root@vikas ~]#
IP
Edit file /etc/sysconfig/network-scripts/ifcfg-eth(n)
[root@vikas network-scripts]# cat ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:40:F4:C1:F0:BB
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.4.13
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
BROADCAST=192.168.4.255
NETWORK=192.168.4.0
GATEWAY=192.168.4.254
[root@vikas network-scripts]#
OR use the cmd and edit the host name, ip and dns
neat
system-config-network or
system-config-network-tui or
system-config-network-gui
File to Set up clock:
/etc/sysconfig/clock
[root@vikas ~]# cat /etc/sysconfig/clock
ZONE="Asia/Calcutta"
UTC=true
[root@vikas ~]#
[root@vikas ~]# cat /etc/sysconfig/clock
ZONE="Asia/Calcutta"
UTC=true
[root@vikas ~]#
File to Set up clock:
/etc/sysconfig/clock
[root@vikas ~]# cat /etc/sysconfig/clock
ZONE="Asia/Calcutta"
UTC=true
[root@vikas ~]#
[root@vikas ~]# cat /etc/sysconfig/clock
ZONE="Asia/Calcutta"
UTC=true
[root@vikas ~]#
Friday, January 23, 2009
Hidden input in linux script i.e a password input
In this 2nd line (read) will accept input from terminal and stores in pass variable.
But input does not appear on the terminal.
Command used is :- stty - which changes and print terminal line settings
stty -echo;
read -p "Enter Password -" pass
echo -e
stty echo;
But input does not appear on the terminal.
Command used is :- stty - which changes and print terminal line settings
stty -echo;
read -p "Enter Password -" pass
echo -e
stty echo;
Hidden input in linux script i.e a password input
In this 2nd line (read) will accept input from terminal and stores in pass variable.
But input does not appear on the terminal.
Command used is :- stty - which changes and print terminal line settings
stty -echo;
read -p "Enter Password -" pass
echo -e
stty echo;
But input does not appear on the terminal.
Command used is :- stty - which changes and print terminal line settings
stty -echo;
read -p "Enter Password -" pass
echo -e
stty echo;
Thursday, January 22, 2009
sed examples Text manupulation using the sed
SED is very powerful command in context of text manupulation
sed 's/string1/string2/g' ------ Replace string1 with string2
sed 's/\(.*\)1/\12/g' ---------------Modify anystring1 to anystring2
sed '/ *#/d; /^ *$/d' ---------Remove comments and blank lines
sed ':a; /\\$/N; s/\\\n//; ta' ----------- Concatenate lines with trailing \
sed 's/[ \t]*$//' ----------Remove trailing spaces from lines
sed 's/\([\\`\\"$\\\\]\)/\\\1/g' --Escape shell meta characters active within double quotes
seq 10 | sed "s/^/ /; s/ *\(.\{7,\}\)/\1/" ---------Right align numbers
sed -n '1000p;1000q' ----------Print 1000th line
sed -n '10,20p;20q' -----------Print lines 10 to 20
\(.*\) sed -n 's/.*<\/title>.*/\1/ip;T;q' ------------Extract title from HTML web page
sed -i 42d ~/.ssh/known_hosts ---------------Delete a particular line
sed 's/string1/string2/g' ------ Replace string1 with string2
sed 's/\(.*\)1/\12/g' ---------------Modify anystring1 to anystring2
sed '/ *#/d; /^ *$/d' ---------Remove comments and blank lines
sed ':a; /\\$/N; s/\\\n//; ta' ----------- Concatenate lines with trailing \
sed 's/[ \t]*$//' ----------Remove trailing spaces from lines
sed 's/\([\\`\\"$\\\\]\)/\\\1/g' --Escape shell meta characters active within double quotes
seq 10 | sed "s/^/ /; s/ *\(.\{7,\}\)/\1/" ---------Right align numbers
sed -n '1000p;1000q' ----------Print 1000th line
sed -n '10,20p;20q' -----------Print lines 10 to 20
sed -i 42d ~/.ssh/known_hosts ---------------Delete a particular line
sed examples Text manupulation using the sed
SED is very powerful command in context of text manupulation
sed 's/string1/string2/g' ------ Replace string1 with string2
sed 's/\(.*\)1/\12/g' ---------------Modify anystring1 to anystring2
sed '/ *#/d; /^ *$/d' ---------Remove comments and blank lines
sed ':a; /\\$/N; s/\\\n//; ta' ----------- Concatenate lines with trailing \
sed 's/[ \t]*$//' ----------Remove trailing spaces from lines
sed 's/\([\\`\\"$\\\\]\)/\\\1/g' --Escape shell meta characters active within double quotes
seq 10 | sed "s/^/ /; s/ *\(.\{7,\}\)/\1/" ---------Right align numbers
sed -n '1000p;1000q' ----------Print 1000th line
sed -n '10,20p;20q' -----------Print lines 10 to 20
\(.*\) sed -n 's/.*<\/title>.*/\1/ip;T;q' ------------Extract title from HTML web page
sed -i 42d ~/.ssh/known_hosts ---------------Delete a particular line
sed 's/string1/string2/g' ------ Replace string1 with string2
sed 's/\(.*\)1/\12/g' ---------------Modify anystring1 to anystring2
sed '/ *#/d; /^ *$/d' ---------Remove comments and blank lines
sed ':a; /\\$/N; s/\\\n//; ta' ----------- Concatenate lines with trailing \
sed 's/[ \t]*$//' ----------Remove trailing spaces from lines
sed 's/\([\\`\\"$\\\\]\)/\\\1/g' --Escape shell meta characters active within double quotes
seq 10 | sed "s/^/ /; s/ *\(.\{7,\}\)/\1/" ---------Right align numbers
sed -n '1000p;1000q' ----------Print 1000th line
sed -n '10,20p;20q' -----------Print lines 10 to 20
sed -i 42d ~/.ssh/known_hosts ---------------Delete a particular line
Wednesday, January 21, 2009
linux script using while e.g script for table from one to ten, input from command line
#!/bin/sh
#
#Script == testing while statement
#
#
if [ $# -eq 0 ]
then
echo "Error - Number missing form command line argument"
echo "Syntax : $0 number"
echo "Use to print multiplication table for given number"
exit 1
fi
# $1 is first command line argument
n=$1
i=1
while [ $i -le 10 ]
do
echo "$n * $i = `expr $i \* $n`"
#or use bc command
#echo "$n * $i = `echo $i*$n | bc`"
i=`expr $i + 1`
#or
# i=$(($i+1))
done
#
#Script == testing while statement
#
#
if [ $# -eq 0 ]
then
echo "Error - Number missing form command line argument"
echo "Syntax : $0 number"
echo "Use to print multiplication table for given number"
exit 1
fi
# $1 is first command line argument
n=$1
i=1
while [ $i -le 10 ]
do
echo "$n * $i = `expr $i \* $n`"
#or use bc command
#echo "$n * $i = `echo $i*$n | bc`"
i=`expr $i + 1`
#or
# i=$(($i+1))
done
linux script using while e.g script for table from one to ten, input from command line
#!/bin/sh
#
#Script == testing while statement
#
#
if [ $# -eq 0 ]
then
echo "Error - Number missing form command line argument"
echo "Syntax : $0 number"
echo "Use to print multiplication table for given number"
exit 1
fi
# $1 is first command line argument
n=$1
i=1
while [ $i -le 10 ]
do
echo "$n * $i = `expr $i \* $n`"
#or use bc command
#echo "$n * $i = `echo $i*$n | bc`"
i=`expr $i + 1`
#or
# i=$(($i+1))
done
#
#Script == testing while statement
#
#
if [ $# -eq 0 ]
then
echo "Error - Number missing form command line argument"
echo "Syntax : $0 number"
echo "Use to print multiplication table for given number"
exit 1
fi
# $1 is first command line argument
n=$1
i=1
while [ $i -le 10 ]
do
echo "$n * $i = `expr $i \* $n`"
#or use bc command
#echo "$n * $i = `echo $i*$n | bc`"
i=`expr $i + 1`
#or
# i=$(($i+1))
done
Integration of sipx and MS Exchange
Here are the possible requirements to install the Ms Exchange
configure active directory
Set domain name and host name for the machine
Install .NET Framework 2.0 - Installed
Install Microsoft Management Console (MMC)
Install Microsoft Windows PowerShell
Install Microsoft Exchange Server 2007
IIS (Internet Information Server)
After successful installation of the MS Exchange open the management console. sine can open it from Start -> Program -> MS Exchange Server 2007 -> Exchange management Console
This will open GUI to manage the Exchange.
Start -> Program -> MS Exchange Server 2007 -> Exchange management Shell
This will open terminal to manage the Exchange.
This will open GUI to manage the Exchange.
Start -> Program -> MS Exchange Server 2007 -> Exchange management Shell
This will open terminal to manage the Exchange.
Integrate the MS Exchange with IPPBX
MS Exchange configurations
MS Exchange configurations
After installing the Unified Messaging Role, either at the initial installation of the server, or at a later time, using the Add/Remove Programs control panel applet and clicking the Change button on the Exchange 2007 program entry. The following tasks all use the Exchange Management Shell, but can just as easily be configured using the Exchange Management Console GUI.
- Create the Dial Plan, using a 3 digit internal numbering scheme. You can use as many digits as you like (just be sure to adjust all the extension numbers in the rest of the document to use that amount). We will use the number '121' as the extension subscribers (the term for users with UM enabled Mailboxes) to access Outlook Voice Access.
new-UMDialPlan -Name:'3DigitDialPlan' -NumberOfDigitsInExtension:'3' -AccessTelephoneNumbers 121
- Create the gateway entry to the sipX server.
new-UMIPGateway -Name:'sipx' -Address:'sipx.server.com/ipofserver -UMDialPlan:'3DigitDialPlan'
- Create the AutoAttendant, and make it accessible on extension '122'
new-UMAutoAttendant -Name:'AutoAttendant' -UMDialPlan:'3DigitDialPlan' -PilotIdentifierList:'122' -Status:'Enabled' -SpeechEnabled:$true
- Modify the settings of the Auto Attendant. These can be customized as you desire. This command is not necessary. This will make 200 as your auto attendant.
Set-UMAutoAttendant -Identity AutoAttendant -AfterHoursTransferToOperatorEnabled $true -AllowExtensions $true -BusinessHoursTransferToOperatorEnabled $true -CallSomeoneEnabled $true -NameLookupEnabled $true -SendVoiceMsgEnabled $true -OperatorExtension '200' -ContactScope GlobalAddressList
For this AA operator 200 must be there. Make some more AA dont assign them any operator. One can make AA from the console as well.
- Associate the dial plan with the server to make it active. Replace the server shown below with the FQDN of your UM server
Set-UMServer –Identity:'msexchange.server.com' -DialPlans 3DigitDialPlan
- Enable UM for your mailbox users, and associate an extension for them. Associate yourself the 200 extensions to allow testing and to receive calls that are transferred to the operator. Replace DOMAIN\Username with your own user account details, and the 'Pin' value with one of your choosing. To edit these policy settings, open the Exchange Management Console, expand Organization Configuration, Unified Messaging, and click the UM Mailbox Policies tab.
Enable-UMMailbox -Identity:'DOMAIN\yourusername' -UMMailboxPolicy:'3DigitDialPlan Default Policy' –Extensions 200 -Pin 893465 -PinExpired $false
Like this all the user of sipx must be associate with the user of exchange.
IPPBX configurations
The following provides instructions on how to integrate IPPBX with Microsoft Exchange 2007 for VM and AA applications. Microsoft Exchange 2007 is a speech enabled application able to serve as a Voice Mail or auto-Attendant server. In addition, it can read your email or provide voice enabled access to your calendar.
A) Give a User or Group of Users Permission to use Exchange VM as their Voice mail System :-
On a per user basis or for an entire group of users the administrator can select Microsoft Exchange as the voice mail system.
For that go to the configuration screen for the respective user and select "Permission" from the left navigation menu. Scroll all the way down until you see the fields for voice mail permission.
Now from here select the second option and apply.
B) Create a Dial plan Rule for the Microsoft Exchange 2007 Server :-
If all the users on this system use Microsoft Exchange 2007 as their voice mail system, then change the default voice mail rule in the dial plan to indicate that Exchange 2007 is selected as the voice mail server. If both Exchange 2007 and the PBX voice mail system shall be used simultaneously then a second voice mail dialing rule has to be created that designates Microsoft Exchange 2007 as the voice mail server. A different voice mail extension and prefix have to be chosen for one of the voice mail servers.
Goto System --> Dial Plan
Dial Plan window will be displayed. Click on the voice mail dial plan which will open the voice mail windows as below.
Select the "Voice mail" rule or create a new one (there can be several voice mail rules in a system if you have more than one voice mail system).
Here we got 2 options
Voice mail type – which should be now Exchange Voice mail server
Voice mail host – where the MS Exchange server is installed. Host name of that server should be given here.
Now apply that settings.
C) Integration
Two steps are required to add the Microsoft Exchange 2007 Auto-Attendant as a system auto-attendant to PBX:
a) Create a new SIP Trunk Gateway that points at the Microsoft Exchange 2007 Server. Choose TCP as the transport protocol under advanced settings.
For this goto :
Devices --> Gateways
This will open the gateway page. Now select the 'SIP trunk' as the gateway from the available list of gateways.
Now fill up the all the options i.e name, Address etc.
By clicking on 'Show Advance Settings' Transport Protocol setting will be available. Give TCP in the Transport Protocol.
Now Apply the settings.
b) Create a Dial Plan
Create a new Custom dialing rule that routes calls with a specific number to the Exchange AA Server. For that goto
System --> Dial Plans
Select the Custom Dial Plan from the dial plan list.
Fill all the options there, name, dialed number, etc. Also add the Gateway added for the ms exchange. Apply the settings.
The number define here when dialed, will route the call to the MS Exchange unified messaging server.
c) Configure the Fully Qualified Domain Name
Click the System menu and the Domain menu item, and enter the fully qualified domain name that the PBX server will use. When prompted, ensure you activate the new dial plans for our configuration changes to take effect.
Also the FQDN must be the same as the value you configured as the UM IP Gateway address on the Exchange UM Server.
4.3 Configure the SIP client
Now that we have configured the Exchange UM Services and the basic PBX services, we can test to see if our configuration is working. Configure SIP client as:-
Display Name: Your Name
User name: 300
Password: SIP Password you entered in PBX for the test extension
Authorization user name Leave Blank
Domain: PBX host name
User name: 300
Password: SIP Password you entered in PBX for the test extension
Authorization user name Leave Blank
Domain: PBX host name
4.4 Testing the Initial Call
Now in order to test that what we have setup so far is working, dial extension 300. This tests that we have correctly registered with PBX for incoming calls. You should see an incoming call on line 2.
In order to test the connection to the Exchange Server, dial 222, and the UM server should pick up and say "Welcome, you are connected to Microsoft Exchange". As long as you set your extension to 300 when you enabled your mailbox from UM, Exchange will detect that you are calling from 300, greet you by name, and simply prompt for your PIN. Now you can test the capabilities of Outlook Voice Access and navigate through the menus.
To confirm that we have setup the auto attendant correctly, dial 299, and the UM server should pick up and say "Welcome to the Microsoft Exchange Auto Attendant. To reach a specific person, just tell me their name". If you speak the name of someone in the directory, it will try to call them. As we have not completed our setup, it will divert to voice mail. If you leave a voice mail, it will appear in your Outlook in box.
Integration of sipx and MS Exchange
Here are the possible requirements to install the Ms Exchange
configure active directory
Set domain name and host name for the machine
Install .NET Framework 2.0 - Installed
Install Microsoft Management Console (MMC)
Install Microsoft Windows PowerShell
Install Microsoft Exchange Server 2007
IIS (Internet Information Server)
After successful installation of the MS Exchange open the management console. sine can open it from Start -> Program -> MS Exchange Server 2007 -> Exchange management Console
This will open GUI to manage the Exchange.
Start -> Program -> MS Exchange Server 2007 -> Exchange management Shell
This will open terminal to manage the Exchange.
This will open GUI to manage the Exchange.
Start -> Program -> MS Exchange Server 2007 -> Exchange management Shell
This will open terminal to manage the Exchange.
Integrate the MS Exchange with IPPBX
MS Exchange configurations
MS Exchange configurations
After installing the Unified Messaging Role, either at the initial installation of the server, or at a later time, using the Add/Remove Programs control panel applet and clicking the Change button on the Exchange 2007 program entry. The following tasks all use the Exchange Management Shell, but can just as easily be configured using the Exchange Management Console GUI.
- Create the Dial Plan, using a 3 digit internal numbering scheme. You can use as many digits as you like (just be sure to adjust all the extension numbers in the rest of the document to use that amount). We will use the number '121' as the extension subscribers (the term for users with UM enabled Mailboxes) to access Outlook Voice Access.
new-UMDialPlan -Name:'3DigitDialPlan' -NumberOfDigitsInExtension:'3' -AccessTelephoneNumbers 121
- Create the gateway entry to the sipX server.
new-UMIPGateway -Name:'sipx' -Address:'sipx.server.com/ipofserver -UMDialPlan:'3DigitDialPlan'
- Create the AutoAttendant, and make it accessible on extension '122'
new-UMAutoAttendant -Name:'AutoAttendant' -UMDialPlan:'3DigitDialPlan' -PilotIdentifierList:'122' -Status:'Enabled' -SpeechEnabled:$true
- Modify the settings of the Auto Attendant. These can be customized as you desire. This command is not necessary. This will make 200 as your auto attendant.
Set-UMAutoAttendant -Identity AutoAttendant -AfterHoursTransferToOperatorEnabled $true -AllowExtensions $true -BusinessHoursTransferToOperatorEnabled $true -CallSomeoneEnabled $true -NameLookupEnabled $true -SendVoiceMsgEnabled $true -OperatorExtension '200' -ContactScope GlobalAddressList
For this AA operator 200 must be there. Make some more AA dont assign them any operator. One can make AA from the console as well.
- Associate the dial plan with the server to make it active. Replace the server shown below with the FQDN of your UM server
Set-UMServer –Identity:'msexchange.server.com' -DialPlans 3DigitDialPlan
- Enable UM for your mailbox users, and associate an extension for them. Associate yourself the 200 extensions to allow testing and to receive calls that are transferred to the operator. Replace DOMAIN\Username with your own user account details, and the 'Pin' value with one of your choosing. To edit these policy settings, open the Exchange Management Console, expand Organization Configuration, Unified Messaging, and click the UM Mailbox Policies tab.
Enable-UMMailbox -Identity:'DOMAIN\yourusername' -UMMailboxPolicy:'3DigitDialPlan Default Policy' –Extensions 200 -Pin 893465 -PinExpired $false
Like this all the user of sipx must be associate with the user of exchange.
IPPBX configurations
The following provides instructions on how to integrate IPPBX with Microsoft Exchange 2007 for VM and AA applications. Microsoft Exchange 2007 is a speech enabled application able to serve as a Voice Mail or auto-Attendant server. In addition, it can read your email or provide voice enabled access to your calendar.
A) Give a User or Group of Users Permission to use Exchange VM as their Voice mail System :-
On a per user basis or for an entire group of users the administrator can select Microsoft Exchange as the voice mail system.
For that go to the configuration screen for the respective user and select "Permission" from the left navigation menu. Scroll all the way down until you see the fields for voice mail permission.
Now from here select the second option and apply.
B) Create a Dial plan Rule for the Microsoft Exchange 2007 Server :-
If all the users on this system use Microsoft Exchange 2007 as their voice mail system, then change the default voice mail rule in the dial plan to indicate that Exchange 2007 is selected as the voice mail server. If both Exchange 2007 and the PBX voice mail system shall be used simultaneously then a second voice mail dialing rule has to be created that designates Microsoft Exchange 2007 as the voice mail server. A different voice mail extension and prefix have to be chosen for one of the voice mail servers.
Goto System --> Dial Plan
Dial Plan window will be displayed. Click on the voice mail dial plan which will open the voice mail windows as below.
Select the "Voice mail" rule or create a new one (there can be several voice mail rules in a system if you have more than one voice mail system).
Here we got 2 options
Voice mail type – which should be now Exchange Voice mail server
Voice mail host – where the MS Exchange server is installed. Host name of that server should be given here.
Now apply that settings.
C) Integration
Two steps are required to add the Microsoft Exchange 2007 Auto-Attendant as a system auto-attendant to PBX:
a) Create a new SIP Trunk Gateway that points at the Microsoft Exchange 2007 Server. Choose TCP as the transport protocol under advanced settings.
For this goto :
Devices --> Gateways
This will open the gateway page. Now select the 'SIP trunk' as the gateway from the available list of gateways.
Now fill up the all the options i.e name, Address etc.
By clicking on 'Show Advance Settings' Transport Protocol setting will be available. Give TCP in the Transport Protocol.
Now Apply the settings.
b) Create a Dial Plan
Create a new Custom dialing rule that routes calls with a specific number to the Exchange AA Server. For that goto
System --> Dial Plans
Select the Custom Dial Plan from the dial plan list.
Fill all the options there, name, dialed number, etc. Also add the Gateway added for the ms exchange. Apply the settings.
The number define here when dialed, will route the call to the MS Exchange unified messaging server.
c) Configure the Fully Qualified Domain Name
Click the System menu and the Domain menu item, and enter the fully qualified domain name that the PBX server will use. When prompted, ensure you activate the new dial plans for our configuration changes to take effect.
Also the FQDN must be the same as the value you configured as the UM IP Gateway address on the Exchange UM Server.
4.3 Configure the SIP client
Now that we have configured the Exchange UM Services and the basic PBX services, we can test to see if our configuration is working. Configure SIP client as:-
Display Name: Your Name
User name: 300
Password: SIP Password you entered in PBX for the test extension
Authorization user name Leave Blank
Domain: PBX host name
User name: 300
Password: SIP Password you entered in PBX for the test extension
Authorization user name Leave Blank
Domain: PBX host name
4.4 Testing the Initial Call
Now in order to test that what we have setup so far is working, dial extension 300. This tests that we have correctly registered with PBX for incoming calls. You should see an incoming call on line 2.
In order to test the connection to the Exchange Server, dial 222, and the UM server should pick up and say "Welcome, you are connected to Microsoft Exchange". As long as you set your extension to 300 when you enabled your mailbox from UM, Exchange will detect that you are calling from 300, greet you by name, and simply prompt for your PIN. Now you can test the capabilities of Outlook Voice Access and navigate through the menus.
To confirm that we have setup the auto attendant correctly, dial 299, and the UM server should pick up and say "Welcome to the Microsoft Exchange Auto Attendant. To reach a specific person, just tell me their name". If you speak the name of someone in the directory, it will try to call them. As we have not completed our setup, it will divert to voice mail. If you leave a voice mail, it will appear in your Outlook in box.
Parsing XML file, using ruby from terminal
This command will display contents of a particular tag of the specified xml file
$ruby -e 'require "rexml/document"; include REXML; Document.new(File.new("filepath.xml")).elements[1].elements.each {|x| puts x.elements["tagname"] }'
$ruby -e 'require "rexml/document"; include REXML; Document.new(File.new("filepath.xml")).elements[1].elements.each {|x| puts x.elements["tagname"] }'
Parsing XML file, using ruby from terminal
This command will display contents of a particular tag of the specified xml file
$ruby -e 'require "rexml/document"; include REXML; Document.new(File.new("filepath.xml")).elements[1].elements.each {|x| puts x.elements["tagname"] }'
$ruby -e 'require "rexml/document"; include REXML; Document.new(File.new("filepath.xml")).elements[1].elements.each {|x| puts x.elements["tagname"] }'
wget example - to download a clip from you tube using the terminal
Use the address on the address bar in this command
1) wget -O /tmp/page.tmp http://www.youtube.com/watch?v=DwVZeCLEWrE
2) cat /tmp/page.tmp | grep video_id=
This will be the output
1) wget -O /tmp/page.tmp http://www.youtube.com/watch?v=DwVZeCLEWrE
2) cat /tmp/page.tmp | grep video_id=
This will be the output
var fullscreenUrl = '/watch_fullscreen?video_id=UHvAXLBMWGI&l=51&t= OEgsToPDskKBFLkte03dOnia39Rzd6 3j&sk=7Ayx8rGROMLJrkh6LkXj7AC& fs=1&title=CompizFusion';
var relatedVideoGridUrl = '/related_ajax?video_id=UHvAXLBMWGI&view_type=G& watch3=1&search=compiz% 20linux%20ubuntu';
var relatedVideoListUrl = '/related_ajax?video_id=UHvAXLBMWGI&view_type=L& watch3=1&search=compiz% 20linux%20ubuntu';
Now use the video_id of first line.
3) wget -O /root/Desktop/clip.flv 'http://www.youtube.com/get_video?video_id=UHvAXLBMWGI&l= '51&t= OEgsToPDskKBFLkte03dOnia39Rzd6 3j&sk=7Ayx8rGROMLJrkh6LkXj7AC& fs=1&title=CompizFusion
This will download that particular video.
Subscribe to:
Comments (Atom)