as root , i want to untar specific.tar.gz to all home user directory
and after untar , there is 1.txt 2.txt ~~ 26.txt in/public_html/test1/
i want randomly selected 6 text files in 1.txt 2.txt ~26.txt to be renamed
newword1.word , newword2.word , ~~ newword6.word .
and change all file chown user1:user1
user2:user2 .........
My preferred method of dealing with things like this is to do in 2 or 3 steps,
not all at once.
Here's the first script:
#!/bin/ksh
#----------------------------------------------------------------------#
# head to home partition. #
#----------------------------------------------------------------------#
cd /home
/bin/ls |
while read dir ; do
#----------------------------------------------------------------------#
# Not a directory, next.... #
#----------------------------------------------------------------------#
if [ ! -d $dir ]; then
continue
fi
cd $dir
#----------------------------------------------------------------------#
# Untar the tar file.... #
#----------------------------------------------------------------------#
cp /fullpath/tar_file.gz .
gunzip tar_file.gz
chmod -R *
cd /home
done | tee /tmp/log1
Once that thing is debugged and working correctly,
I use a code generator to create the next dangerous type commands:
( mv commands in this case.... )
#!/bin/ksh
#----------------------------------------------------------------------#
# head to home partition. #
#----------------------------------------------------------------------#
cd /home
/bin/ls |
while read dir ; do
cd /home/$dir/public_html/test1
#----------------------------------------------------------------------#
# Randomly rename 6 files. #
#----------------------------------------------------------------------#
num=0
/bin/ls *.txt |
while read file_nm ; do
(( check = $RANDOM % 2 ))
if [ $check -eq 0 ]; then
continue
fi
(( num = num + 1 ))
echo /bin/mv $PWD/$file_nm $PWD/newword${num}.word
if [ $num -ge 6 ]; then
break
fi
done ### while doing random renaming....
cd /home
done |
tee /tmp/log2
Then, before executing, I examine the contents of /tmp/log2.
If the commands in there look right --- then I execute that script with:
/bin/ksh -xvf /tmp/log2 2>&1 | tee /tmp/log3
Using this method decreases the risk incurred at each step and
provides a log for each step also.
why not ls? are you worried about performance again?
fullpaths are safest and using them means you're less likely to put something
somewhere unintended.
oops:
chmod -R 755 *
Preferred would be to unzip the tarball elsewhere, I suppose, then
get fancy with the tar -xvf command and redirection.
I've had other posters complain when I use your syntax that it's not standard.
So. I give up. Let the original poster do some of the work. It won't kill them.
#!/bin/ksh
while read line
do
cd $line/radmin
num=0
/bin/ls *.txt |
while read file_nm ; do
\(\( check = $RANDOM % 2 \)\)
if [ $check -eq 0 ]; then
continue
fi
\(\( num = num \+ 1 \)\)
echo /bin/cp $PWD/$file_nm $PWD/newword$\{num\}.word
if [ $num -ge 6 ]; then
break
fi