#!/bin/bash
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Promote to Production</title></head>"
echo "<body>"
sourceroot=/qa_webroot
targetroot=/t3psolarweb202
lines=0
#-- Define table, log, and error files.
#-- All file operation commands should redirect stdout
#-- to LOG and stderr to ERROR
#-- i.e. command 1>>$LOG 2>>$ERROR
#
#-- Magic CGI stuff here... Get the path from the users
#-- promote web form...
SEED=`date +%s%N`
ERROR=/tmp/$SEED.err
LOG=/tmp/$SEED.xfer
TABLE=${sourceroot}`echo -n $QUERY_STRING | sed -n 's/^.*tablepath=\([^&]*\).*$/\1/p' | sed 's/%2F/\//g'`
echo "<h2>Promoting $TABLE contents to production now</h2>"
#-- Ensure the tablefile is workable
dos2unix -q $TABLE 1>>$LOG 2>>$ERROR
#chown solarweb:sysadmin $TABLE 1>>$LOG 2>>$ERROR
#-- Start main loop through of table
for line in `cat $TABLE`
do
source=$sourceroot`echo $line | awk -F \| '{ print $1 }';`
target=$targetroot`echo $line | awk -F \| '{ print $2 }';`
#-- DEBUG
echo "Source from $TABLE is $source"
echo "Target from $TABLE is $target"
#-- END DEBUG
echo >> $LOG
echo `date` - $source to $target >> $LOG
echo >> $LOG
#-- Make destianation if source is a directory and target doesn't exist
[ -d $source -a ! -e $target ]&& mkdir -p $target 1>>$LOG 2>>$ERROR
#-- Now copy the matching files from source to target
# rsync -vrultD --min-size=10 --delete-after --exclude=Thumbs.db --exclude=promote/ $source $target 1>>$LOG 2>>$ERROR
rsync -vrultD --min-size=10 --exclude=Thumbs.db --exclude=promote/ --exclude=tid-cgi-bin/ $source $target 1>>$LOG 2>>$ERROR
#-- Set permissions on target
chown -R solarweb:solarweb $target 1>>$LOG 2>>$ERROR
find $target -type d -exec chmod 775 {} \; 1>>$LOG 2>>$ERROR
if [ `echo $line | grep -c cgi` -gt 0 ];then
find $target -type f -exec chmod 775 {} \; 1>>$LOG 2>>$ERROR
else
find $target -type f -exec chmod 664 {} \; 1>>$LOG 2>>$ERROR
fi
find $target -name Thumbs.db -exec rm -f {} \; 1>>$LOG 2>>$ERROR
done
echo "<b>Transferred</b><br>"
echo "<hr>"
unix2dos -q $LOG 1>>$LOG 2>>$ERROR
echo "<pre>"
cat $LOG
echo "<hr>"
echo "<b>Errors<b><br>"
unix2dos -q $ERROR 2>>$ERROR
cat $ERROR
echo "</pre>
echo "<hr>"
rm $ERROR $LOG
echo "</body></html>"
A Trip through Linux
by Ken Sipe
Thursday, August 3, 2017
Friday, May 5, 2017
Bash - Scripting - Converting file name to web ready file name
#!/bin/bash
#
# web_ready.sh
#
if [ "${1}" ]
then
extension=$( echo "${1}" | awk -F . '{print $NF}' )
mv "${1}" $( echo "${1}" | iconv -f utf-8 -t ascii//translit | tr -d '[:punct:]' | tr [:upper:] [:lower:] | sed "s/${extension}$/.$extension/" | tr ' ' '-')
# echo $(echo "${1}" | tr [:upper:] [:lower:])
# echo "$extension"
else
echo "Enter file"
fi
#
# web_ready.sh
#
if [ "${1}" ]
then
extension=$( echo "${1}" | awk -F . '{print $NF}' )
mv "${1}" $( echo "${1}" | iconv -f utf-8 -t ascii//translit | tr -d '[:punct:]' | tr [:upper:] [:lower:] | sed "s/${extension}$/.$extension/" | tr ' ' '-')
# echo $(echo "${1}" | tr [:upper:] [:lower:])
# echo "$extension"
else
echo "Enter file"
fi
Results:
#web_ready.sh "What They Know, What You Don't.pdf"
#ls -ltr
# what-they-know-what-you-dont.pdf
Monday, April 10, 2017
Bash - Scriptiing - for loop: rename files
#!/bin/bash
#
DIR=/home/kensipe/sbin/data.d/tmp
for file in $DIR/*.A
do
mv "$file" "${file/.A/.B}"
done
Results:
[kensipe@localhost tmp]$ ls -l
total 0
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.5o5P.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.aM48.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.JouO.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.Kt4W.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.msAl.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.NIAg.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.r82a.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.rhhO.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.roN3.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.sGjz.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.Wmmv.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.ZAlc.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.zwBy.A
[kensipe@localhost bash.d]$ ./rename1.sh
[kensipe@localhost bash.d]$
[kensipe@localhost tmp]$ ls -l
total 0
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.5o5P.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.aM48.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.JouO.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.Kt4W.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.msAl.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.NIAg.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.r82a.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.rhhO.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.roN3.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.sGjz.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.Wmmv.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.ZAlc.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.zwBy.B
#
DIR=/home/kensipe/sbin/data.d/tmp
for file in $DIR/*.A
do
mv "$file" "${file/.A/.B}"
done
Results:
[kensipe@localhost tmp]$ ls -l
total 0
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.5o5P.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.aM48.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.JouO.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.Kt4W.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.msAl.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.NIAg.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.r82a.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.rhhO.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.roN3.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.sGjz.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.Wmmv.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.ZAlc.A
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.zwBy.A
[kensipe@localhost bash.d]$ ./rename1.sh
[kensipe@localhost bash.d]$
[kensipe@localhost tmp]$ ls -l
total 0
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.5o5P.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.aM48.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.JouO.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.Kt4W.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.msAl.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.NIAg.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.r82a.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.rhhO.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.roN3.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.sGjz.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.Wmmv.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.ZAlc.B
-rw-------. 1 kensipe kensipe 0 Apr 10 16:38 file.zwBy.B
Bash Scripting - for loop: find files in directory
#!/bin/bash
#
DIR=/home/kensipe/sbin/data.d/tmp
for file in "$DIR/*.A"
do
printf "%s \n" $file
done
Results:
[kensipe@localhost bash.d]$ ./rename.sh
/home/kensipe/sbin/data.d/tmp/file.5o5P.A
/home/kensipe/sbin/data.d/tmp/file.aM48.A
/home/kensipe/sbin/data.d/tmp/file.JouO.A
/home/kensipe/sbin/data.d/tmp/file.Kt4W.A
/home/kensipe/sbin/data.d/tmp/file.msAl.A
/home/kensipe/sbin/data.d/tmp/file.NIAg.A
/home/kensipe/sbin/data.d/tmp/file.r82a.A
/home/kensipe/sbin/data.d/tmp/file.rhhO.A
/home/kensipe/sbin/data.d/tmp/file.roN3.A
/home/kensipe/sbin/data.d/tmp/file.sGjz.A
/home/kensipe/sbin/data.d/tmp/file.Wmmv.A
/home/kensipe/sbin/data.d/tmp/file.ZAlc.A
/home/kensipe/sbin/data.d/tmp/file.zwBy.A
#
DIR=/home/kensipe/sbin/data.d/tmp
for file in "$DIR/*.A"
do
printf "%s \n" $file
done
Results:
[kensipe@localhost bash.d]$ ./rename.sh
/home/kensipe/sbin/data.d/tmp/file.5o5P.A
/home/kensipe/sbin/data.d/tmp/file.aM48.A
/home/kensipe/sbin/data.d/tmp/file.JouO.A
/home/kensipe/sbin/data.d/tmp/file.Kt4W.A
/home/kensipe/sbin/data.d/tmp/file.msAl.A
/home/kensipe/sbin/data.d/tmp/file.NIAg.A
/home/kensipe/sbin/data.d/tmp/file.r82a.A
/home/kensipe/sbin/data.d/tmp/file.rhhO.A
/home/kensipe/sbin/data.d/tmp/file.roN3.A
/home/kensipe/sbin/data.d/tmp/file.sGjz.A
/home/kensipe/sbin/data.d/tmp/file.Wmmv.A
/home/kensipe/sbin/data.d/tmp/file.ZAlc.A
/home/kensipe/sbin/data.d/tmp/file.zwBy.A
Bash - Scripting - part 2- replace part of string
1 #!/bin/bash
2 #
3 # Change file extensions
4 #
5 FILES=/homeb/d54712/sandbox/scripts/data.d/tmp/*
6
7 # ${file/%.pcx/.jpg}
8
9 CONVERT="$(ls $FILES)"
10 TEMP=$(mktemp)
11 echo "$CONVERT" > $TEMP
12
13
14 while read file
15 do
16 echo ${file/%.pcx/.jpg}
17 done < $TEMP
18
19
Results:
# ls -l
total 0
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135724.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135731.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135732.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135733.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135734.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135735.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135736.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135737.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135739.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135752.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135753.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135754.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135755.pcx
-rw-r--r-- 1 root root 0 Apr 10 13:57 file.135756.pcx
# Convert extensions in temp file ($TEMP)
$ ./file_convert1.sh
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135724.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135731.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135732.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135733.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135734.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135735.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135736.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135737.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135739.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135752.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135753.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135754.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135755.jpg
/homeb/d54712/sandbox/scripts/data.d/tmp/file.135756.jpg
Bash - Scripting - part 1- replace part of string
#!/bin/bash
#
# Change file extensions
#
FILES=/homeb/d54712/sandbox/scripts/data.d/files.txt
exec 3< $FILES
exec <&3
while read file
do
echo "${file/%.pcx/.jpg}"
done
Results:
# cat files.txt
132014.pcx
132023.pcx
132024.pcx
132025.xml
132026.pcx
132026.pcx
132027.xpm
132027.pcx
132027.xml
132028.pdf
132028.pcx
132029.pcx
132029.pcx
132029.pdf
132030.pcx
132030.pcx
132030.pcx
132030.pcx
132031.gif
132031.pcx
132031.pcx
# Convert .pcx to .jpg
./file_convert.sh
132014.jpg
132023.jpg
132024.jpg
132025.xml
132026.jpg
132026.jpg
132027.xpm
132027.jpg
132027.xml
132028.pdf
132028.jpg
132029.jpg
132029.jpg
132029.pdf
132030.jpg
132030.jpg
132030.jpg
132030.jpg
132031.gif
132031.jpg
132031.jpg
#
# Change file extensions
#
FILES=/homeb/d54712/sandbox/scripts/data.d/files.txt
exec 3< $FILES
exec <&3
while read file
do
echo "${file/%.pcx/.jpg}"
done
Results:
# cat files.txt
132014.pcx
132023.pcx
132024.pcx
132025.xml
132026.pcx
132026.pcx
132027.xpm
132027.pcx
132027.xml
132028.pdf
132028.pcx
132029.pcx
132029.pcx
132029.pdf
132030.pcx
132030.pcx
132030.pcx
132030.pcx
132031.gif
132031.pcx
132031.pcx
# Convert .pcx to .jpg
./file_convert.sh
132014.jpg
132023.jpg
132024.jpg
132025.xml
132026.jpg
132026.jpg
132027.xpm
132027.jpg
132027.xml
132028.pdf
132028.jpg
132029.jpg
132029.jpg
132029.pdf
132030.jpg
132030.jpg
132030.jpg
132030.jpg
132031.gif
132031.jpg
132031.jpg
Bash - Scripting - part 1- sort highest with defaults
#!/bin/bash
#
# highest filename [howmany]
# Print howmany highest-numbered lines in file filename
# The input file is assumed to have lines that sart with numbers
#+Default for howmany is 10.
filename=$1
howmany=${2:-10}
sort -nr $filename | head -$howmany
Results:
# howmany defaults to 10
$ ./highest.sh albumns.txt
22 U2
12 Coldplay
11 Aerosmith
9 Kodaline
9 Jackson Browne
8 21 Pilots
7 Michael Jackson
6 Pitbull
6 Elton John
5 Thirty Seconds to Mars
# howmany ($2) is 5
$ ./highest.sh /auto/home/homeb/d54712/sandbox/scripts/data.d/albumns.txt 5
22 U2
12 Coldplay
11 Aerosmith
9 Kodaline
9 Jackson Browne
#
# highest filename [howmany]
# Print howmany highest-numbered lines in file filename
# The input file is assumed to have lines that sart with numbers
#+Default for howmany is 10.
filename=$1
howmany=${2:-10}
sort -nr $filename | head -$howmany
Results:
# howmany defaults to 10
$ ./highest.sh albumns.txt
22 U2
12 Coldplay
11 Aerosmith
9 Kodaline
9 Jackson Browne
8 21 Pilots
7 Michael Jackson
6 Pitbull
6 Elton John
5 Thirty Seconds to Mars
# howmany ($2) is 5
$ ./highest.sh /auto/home/homeb/d54712/sandbox/scripts/data.d/albumns.txt 5
22 U2
12 Coldplay
11 Aerosmith
9 Kodaline
9 Jackson Browne
Subscribe to:
Posts (Atom)