crm()
{
# pass this function the name of the directory that
# you want to backup and remove
if [ -d "$1" ]
then
cd "${1}/../"
else
echo "Directory does not exist"
return 1
fi
PWD=`pwd`
BKPFILES=`find $PWD -type -f`
BKPDIR="$HOME/.Trash"
daten=`date +%Y.%m.%d-%H.%M.%S`
for i in $BKPFILES
do
echo "$i"
DIRNAME="$BKPDIR"`echo ${i%/*}`
FILENAME=`echo ${i##*/}`
mkdir -p "$DIRNAME"
cp -pf "$i" "${DIRNAME}/${FILENAME}.${daten}"
#NEWFILE=`echo "$i" | sed 's|[ \/]|_|g'`
print "$i" "$NEWFILE" " $DIRNAME"
done
rm -rf "$1"
cd -
}
Showing posts with label script. Show all posts
Showing posts with label script. Show all posts
Friday, June 18, 2010
Recycle bin script
Monday, June 14, 2010
Simple Network Test Script
This is a simple script to log network outages on a local network
root@ubuntu:/mnt/root/usr/local/bin# more lifeline
#!/bin/bash
PING='/bin/ping'
EXTHOST1='www.google.com'
EXTHOST2='sun.iwu.edu'
INTHOST='192.168.1.1'
LOG='/var/log/network_outages'
WAITTIME=120
echo "NETWORK STATUS SCRIPT: Started " `date` >> $LOG
while [ 1=1 ]
do
dater=`date +%Y.%m.%d-%H.%M.%S`
$PING -q -c1 $EXTHOST1
ret=$?
echo "RET: $ret"
if [ $ret -ne 0 ]
then
echo "EXTERNAL_PING(1): outage detected $dater" >> $LOG
fi
dater=`date +%Y.%m.%d-%H.%M.%S`
$PING -q -c1 $EXTHOST2
ret=$?
echo "RET: $ret"
if [ $ret -ne 0 ]
then
echo "EXTERNAL_PING(2): outage detected $dater" >> $LOG
fi
$PING -q -c1 $INTHOST
ret=$?
echo "RET: $ret"
if [ $ret -ne 0 ]
then
echo "INTERNAL_PING: outage detected $dater" >> $LOG
fi
sleep $WAITTIME
done
root@ubuntu:/mnt/root/usr/local/bin# more lifeline
#!/bin/bash
PING='/bin/ping'
EXTHOST1='www.google.com'
EXTHOST2='sun.iwu.edu'
INTHOST='192.168.1.1'
LOG='/var/log/network_outages'
WAITTIME=120
echo "NETWORK STATUS SCRIPT: Started " `date` >> $LOG
while [ 1=1 ]
do
dater=`date +%Y.%m.%d-%H.%M.%S`
$PING -q -c1 $EXTHOST1
ret=$?
echo "RET: $ret"
if [ $ret -ne 0 ]
then
echo "EXTERNAL_PING(1): outage detected $dater" >> $LOG
fi
dater=`date +%Y.%m.%d-%H.%M.%S`
$PING -q -c1 $EXTHOST2
ret=$?
echo "RET: $ret"
if [ $ret -ne 0 ]
then
echo "EXTERNAL_PING(2): outage detected $dater" >> $LOG
fi
$PING -q -c1 $INTHOST
ret=$?
echo "RET: $ret"
if [ $ret -ne 0 ]
then
echo "INTERNAL_PING: outage detected $dater" >> $LOG
fi
sleep $WAITTIME
done
Thursday, August 20, 2009
Get File Extension in Shell Script
Returns the last file extension in the file name
echo "thisfile.txt.log"awk -F . '{print $NF}' # returns "log"
http://liquidat.wordpress.com/2007/09/29/short-tip-get-file-extension-in-shell-script/
echo "thisfile.txt.log"awk -F . '{print $NF}' # returns "log"
http://liquidat.wordpress.com/2007/09/29/short-tip-get-file-extension-in-shell-script/
Labels:
awk,
extension,
file extension,
script,
shell
Subscribe to:
Posts (Atom)
