When a file/directory is saved with special character other than underscore('_') then it is difficult to remove/rename it. Inorder to remove that file/directory, first rename to a valid filename.
Procedure:
Goto directory where the file/directory is present.
Run this command:
ls -iltr
copy the inode value associated with that file/directory which you want to rename/remove and put that number in the following command in place of XXXXX and replace newname with your desired filename.
find . -inum XXXXX -exec mv {} newname \;
Sunday, August 31, 2008
Wednesday, August 20, 2008
Shell script to find and replace strings
#!/bin/sh
#Script Find a string and replaces it with another string
if [ $# -eq 0 ]
then
echo
echo "Usage: find_replace.sh find_str replace_str ..."
echo
exit 1
fi
for files in $*; do
if [ "$files" = "$1" -o "$files" = "$2" ]
then
a=1
else
mv $files $files.old
sed 's/'$1'/'$2'/g' $files.old > $files
fi
done
rm *.old 2>/dev/null
#Script Find a string and replaces it with another string
if [ $# -eq 0 ]
then
echo
echo "Usage: find_replace.sh find_str replace_str
echo
exit 1
fi
for files in $*; do
if [ "$files" = "$1" -o "$files" = "$2" ]
then
a=1
else
mv $files $files.old
sed 's/'$1'/'$2'/g' $files.old > $files
fi
done
rm *.old 2>/dev/null
Thursday, August 7, 2008
Script to replace ^M characters in unix
#!/bin/sh
if [ $# -eq 0 ]
then
echo
echo "This script will replace the ^M line breaks from dos"
echo "Usage replace"
echo
exit 1
fi
tr -s "\r" "\n" < $1 >$1.tmp
rm $1
mv $1.tmp $1
chmod u+x $1
Note: Don't forget to remove ^M characters from this script first
if [ $# -eq 0 ]
then
echo
echo "This script will replace the ^M line breaks from dos"
echo "Usage replace
echo
exit 1
fi
tr -s "\r" "\n" < $1 >$1.tmp
rm $1
mv $1.tmp $1
chmod u+x $1
Note: Don't forget to remove ^M characters from this script first
Friday, July 25, 2008
How to get log file from another unix box using shell script
Use run3.sh for getting a remote file to current directory.
cplogs.sh
=========
#!/bin/sh
if [ $# -eq 0 ]
then
echo "Usage: cplogs"
echo "Options"
echo "1: Managed_Server_1.log"
echo "2: Managed_Server_2.log"
echo "3: Managed_Server_3.log"
echo "4: Managed_Server_4.log"
echo "5: Managed_Server_5.log"
exit 1
fi
rm *.log 2>/dev/null
for i in $*
do
case $i in
1) cp /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_1/logs/managedServer_1.log . ;;
2) cp /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_2/logs/managedServer_2.log . ;;
3) cp /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_3/logs/managedServer_3.log . ;;
4) . ./run4.sh ;;
5) . ./run5.sh ;;
esac
done
run3.sh
========
#!/bin/sh
HOST='Ur Ip'
USER='Username'
PASSWD='password'
ftp -n $HOST < quote USER $USER
quote PASS $PASSWD
bi
cd /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_4/logs
get managedServer_4.log
quit
END_SCRIPT
cplogs.sh
=========
#!/bin/sh
if [ $# -eq 0 ]
then
echo "Usage: cplogs
echo "Options"
echo "1: Managed_Server_1.log"
echo "2: Managed_Server_2.log"
echo "3: Managed_Server_3.log"
echo "4: Managed_Server_4.log"
echo "5: Managed_Server_5.log"
exit 1
fi
rm *.log 2>/dev/null
for i in $*
do
case $i in
1) cp /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_1/logs/managedServer_1.log . ;;
2) cp /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_2/logs/managedServer_2.log . ;;
3) cp /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_3/logs/managedServer_3.log . ;;
4) . ./run4.sh ;;
5) . ./run5.sh ;;
esac
done
run3.sh
========
#!/bin/sh
HOST='Ur Ip'
USER='Username'
PASSWD='password'
ftp -n $HOST <
quote PASS $PASSWD
bi
cd /sundev/osmenv01/bea92mp2_user_projects/domains/osm7ClustDomain/servers/managedServer_4/logs
get managedServer_4.log
quit
END_SCRIPT
Monday, July 21, 2008
How to exit all telnet session at one shot
function stopall
{
if [ $# -eq 0 ]
then
echo "stopall"
echo "1:Kill all the Tail process"
echo "2:Kill all the telnet session(including kill tail process)"
else
if [ $1 -eq 1 ]
then
psef|grep "tail"|awk '{print $2}'|xargs kill -9 2>/dev/null
echo "All Tail process are killed"
elif [ $1 -eq 2 ]
then
psef|grep "tail"|awk '{print $2}'|xargs kill -9 2>/dev/null
psef|grep "ksh"|grep -v `echo $$`|awk '{print $2}'|xargs kill -9 2>/dev/null
kill -9 `echo $$`
else
echo "Please provide correct input"
fi
fi
}
{
if [ $# -eq 0 ]
then
echo "stopall
echo "1:Kill all the Tail process"
echo "2:Kill all the telnet session(including kill tail process)"
else
if [ $1 -eq 1 ]
then
psef|grep "tail"|awk '{print $2}'|xargs kill -9 2>/dev/null
echo "All Tail process are killed"
elif [ $1 -eq 2 ]
then
psef|grep "tail"|awk '{print $2}'|xargs kill -9 2>/dev/null
psef|grep "ksh"|grep -v `echo $$`|awk '{print $2}'|xargs kill -9 2>/dev/null
kill -9 `echo $$`
else
echo "Please provide correct input"
fi
fi
}
Subscribe to:
Posts (Atom)