well
( speaking simply , cause simple seems to be as much as i can do
I wish to have a this called as part of a greater shell script
example the most complex script is the backUP itself
where as you can see it is called
down in the script
sudo tar --totals -H pax -cvf /dev/st0 *
( marked in
red )
and of course , you are asked for the root password.
the user experience that i am looking for is when the script is ran
the user is only asked for HIS password ( eg the dog user , the limited user - or no password query-- but NOT for the root password. the idea is this person would not know the root password.
[ also this script below is the most complex thing i have ever made ; could not have done it without google & the good & wise folk found at LINUXQUESTIONS.org
thanks much!
------------start of script named ppsbu.sh
#!/bin/sh
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~# vers 11 ; 2.25.2011 js
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~# backUP
##-----------< assumes a chgrp users of /media
##-----------< assumes a 755 dir of /home/pps/pps_list
#######################################################
###----------------># start is there a tape test
sudo mt -f /dev/st0 status | grep error
if [[ $? -ne error ]]
then
echo "ALERT ========= you need a tape "
exit
else
echo " all is well-- you got a tape"
fi
###----------------># end is there a tape test
#
####----# get JobNum # enter w spaces
echo “Please provide the jobNum -----! 5 digits NO SPACES !”
read jobNum
echo “Thanks…Processing Your ${jobNum} Now”
###---i need a date
start=$(date)
Ntime=$(date)
CalcStart=$(date +%s)
echo $Ntime > /home/pps/pps_list/${jobNum}.txt
#---
#cd /media/*
cd /media/
#echo "dir is: `pwd`"
##-----how big is it # find in Num of bytes the size of dir
dirSize=$(du -bs /media/$jobNum* | awk '{print $1}')
echo $dirSize
##--end how big
####---# make a txt file - later it might get upld--dunno
####-for the tape the 00index.txt
echo $jobNum > /media/00index.txt
echo $Ntime >> /media/00index.txt
ls -Rlh >> /media/00index.txt
###-for big saver
ls -Rlh >> /home/pps/pps_list/${jobNum}.txt
echo $dirSize " bytes" >> /home/pps/pps_list/${jobNum}.txt
ls -R > /home/pps/pps_list/${jobNum}_short.txt
echo $dirSize " Bytes" >> /home/pps/pps_list/${jobNum}_short.txt
####----------------------------------------------------# the do
####----# make tape , assume 0
sudo tar --totals -H pax -cvf /dev/st0 *
###-----# start happytest
if [[ $? -ne 0 ]]
then
echo " backUP halt or error "
exit1
else
############
end=$(date)
CalcEnd=$(date +%s)
echo $end >> /home/pps/pps_list/${jobNum}.txt
diff=$(( $CalcEnd - $CalcStart ))
## my dif effort needs work - need to do min only
#echo "Task Duration "$diff >> /home/pps/pps_list/${jobNum}.txt
####-remove the 00index.txt
rm /media/00index.txt
####----------------------------------------------------# end do
####---------------------------------------------# Start mail
# email subject
SUBJECT="The Back Up Job Number: "$jobNum
# Email To ?
########### group
EMAIL="bu@mydom.com"
########### devel
#EMAIL="me@mydom.com"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "saver drive backed up to tape"> $EMAILMESSAGE
echo ".................................................. " >>$EMAILMESSAGE
echo "the job: " $jobNum >>$EMAILMESSAGE
echo $dirSize " Bytes" >>$EMAILMESSAGE
echo " " >>$EMAILMESSAGE
echo "Start Time: "$start >>$EMAILMESSAGE
echo " " >>$EMAILMESSAGE
echo " End Time: "$(date) >>$EMAILMESSAGE
echo "-------------------------------------------------- " >>$EMAILMESSAGE
echo "machine = armstrong" >>$EMAILMESSAGE
echo ".................................................. " >>$EMAILMESSAGE
echo " " >>$EMAILMESSAGE
echo "total seconds "$diff >>$EMAILMESSAGE
####hour=`echo $diff/3600 | bc`
echo " " >>$EMAILMESSAGE
hour=$(echo $diff/3600 | bc -l)
echo "that is r N $hour hour" >> $EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
#echo "subject is " $SUBJECT
#####----------------------------------------------# end mail
echo "*********************************************************"
echo " . "
echo "backup " ${jobNum} " DONE "
echo " . "
echo "It took "$diff
echo "--------------------------------------------------::good"
fi
###-----# end happytest
####- eject tape ** the whole eject merged w a tell maybe
#sudo mt -f /dev/st0 eject
#mt -f /dev/st0 eject
echo "eject with a 88888 then Label and be sure to Slide the RED for copy PROTECT NOW"