09-20-2016
I tried to write an example clearer:
Code :
date_form1=$(date +'%y-%m-%d') # Variable date format : YYMMDD
date_form2=$(date +'%Y-%m-%d') # Variable date format : YYYYMMDD
height_file1=$(du -h /home/$date_form2/* | sed -n '1p' | cut -c 1-4)
name_file1=$(du -h /home/$date_form2/* | sed -n '1p' | cut -c 6-)
height_file2=$(du -h /home/$date_form2/* | sed -n '2p' | cut -c 1-4)
name_file2=$(du -h /home/$date_form2/* | sed -n '2p' | cut -c 5-)
height_file3=$(du -h /home/$date_form2/* | sed -n '4p' | cut -c 1-4)
name_file3=$(du -h /home/$date_form2/* | sed -n '4p' | cut -c 5-)
height_file4=$(du -h /home/$date_form1/* | cut -c 1-5)
name_file4=$(du -h /home/$date_form1/* | cut -c 6-)
height_file5=$(du -h /home/$date_form1/* | cut -c 1-5)
name_file5=$(du -h /home/$date_form1/* | cut -c 6-)
height_file6=$(du -h /home/file6-$date_form1.tar.gz | cut -c 1-5)
name_file6=$(du -h /home/file6-$date_form1.tar.gz | cut -c 6-)
disk_used=$(df -h | sed -n '9p' | cut -c 23-27)
disk_available=$(df -h | sed -n '9p' | cut -c 29-33)
disk_percent=$(df -h | sed -n '9p' | cut -c 35-38)
fichier1="/home/$date_form2/file1"
fichier2="/home/$date_form2/file2"
fichier3="/home/$date_form2/file3"
fichier4="/home/$date_form1/file4"
fichier5="/home/file5-$date_form1.tar.gz"
fichier6="/home/$date_form1/file6"
affiche () {
if [ $name == "$fichier1" ];
then
: (I wish nothing, No display)
else
echo -e "\nDate : $date_form2\nFile : $name_file1\nHeight : $height_file1\n" ;
fi
if [ $name == "$fichier2" ];
then
: (I wish nothing, No display)
else
echo -e "Date : $date_form2\nFile : $name_file2\nHeight : $height_file2\n" ;
fi
if [ $name == "$fichier3" ];
then
: (I wish nothing, No display)
else
echo -e "Date : $date_form2\nFile : $name_file3\nHeight : $height_file3\n" ;
fi
if [ $name == "$fichier4" ];
then
: (I wish nothing, No display)
else
echo -e "Date : $date_form2\nFile : $name_file4\nHeight : $height_file4\n" ;
fi
if [ $name == "$fichier5" ];
then
: (I wish nothing, No display)
else
echo -e "Date : $date_form2\nFile : $name_file5\nHeight : $height_file5\n" ;
fi
if [ $name == "$fichier6" ];
then
: (I wish nothing, No display)
else
echo -e "Date : $date_form2\nFile : "$name_file6"\nHeight : $height_file6" ;
fi
}
declare -a missing
for name in $fichier1 $fichier2 $fichier3 $fichier4 $fichier5 $fichier6
do
[[ -e $name ]] || missing[${#missing[*]}]=$name
done
if (( ${#missing[*]} == 0 ))
then
echo -e "\nDate : $date_form2\nFile : $name_file1\nHeight : $height_file1\n" ;
echo -e "Date : $date_form2\nFile : $name_file2\nHeight : $height_file2\n" ;
echo -e "Date : $date_form2\nFile : $name_file3\nHeight : $height_file3\n" ;
echo -e "Date : $date_form2\nFile : $name_file4\nHeight : $height_file4\n" ;
echo -e "Date : $date_form2\nFile : $name_file5\nHeight : $height_file5\n" ;
echo -e "Date : $date_form2\nFile : "$name_file6"\nHeight : $height_file6" ;
else
affiche ;
echo -e "\n\nMissing: " ${missing[*]}
fi
echo -e "\nDisk Used : $disk_used\nDisk Available : $disk_available\nDisk Used In Percent : $disk_percent\n" ;
exit 0 ;
Its output :
Code :
Date : 2016-09-19
File : /home/16-09-19/file1
Height : 100K
Date : 2016-09-19
File : /home/16-09-19/file2
Height : 160K
Date : 2016-09-19
File : /home/16-09-19/file3
Height : 4.0K
Date : 2016-09-19
File : /home/16-09-19/file4
Height : 236K
Date : 2016-09-19
File :
Height :
Missing: /home/16-09-19/file6
Disk Used : 39M
Disk Available : 185M
Disk Used In Percent : 18%
I took off the file 6 for provoke the function "affiche", like you note, it misses display of the file 5 and on position of file 6 it's blank.
Me, I would like :
Code :
Date : 2016-09-19
File : /home/16-09-19/file1
Height : 100K
Date : 2016-09-19
File : /home/16-09-19/file2
Height : 160K
Date : 2016-09-19
File : /home/16-09-19/file3
Height : 4.0K
Date : 2016-09-19
File : /home/16-09-19/file4
Height : 236K
Date : 2016-09-19
File : /home/16-09-19/file5
Height : 236K
Missing: /home/16-09-19/file6
Disk Used : 39M
Disk Available : 185M
Disk Used In Percent : 18%
or
Code :
Date : 2016-09-19
File : /home/16-09-19/file1
Height : 100K
Date : 2016-09-19
File : /home/16-09-19/file2
Height : 160K
Date : 2016-09-19
File : /home/16-09-19/file3
Height : 4.0K
Date : 2016-09-19
File : /home/16-09-19/file4
Height : 236K
Date : 2016-09-19
File : /home/16-09-19/file5
Height : 236K
Date : 2016-09-19
File : Missing: /home/16-09-19/file6
Height :
Disk Used : 39M
Disk Available : 185M
Disk Used In Percent : 18%
I hope I have helped you
Last edited by Arnaudh78; 09-20-2016 at 09:09 PM ..
8 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Is there a Unix tool, like in Novell, to recover accidentally deleted files? (2 Replies)
Discussion started by: kuultak
2 Replies
2. AIX
How to recover deleted files in AIX ? (1 Reply)
Discussion started by: vjm
1 Replies
3. UNIX for Dummies Questions & Answers
Hello,
In my shell program, I need to test for a specific size of a text file before it can be imported into an oracle table.
If the size is less than that number, my program should stop processing. What is the correct command to do this test?
Thanks! (1 Reply)
Discussion started by: GEBRAUN
1 Replies
4. Shell Programming and Scripting
Hi All,
I just mistakingly deleted some files using rm command.Is there a way to get it back?i work on Solaris 10
Thanks,
Kumar (1 Reply)
Discussion started by: kumarsaravana_s
1 Replies
5. UNIX for Dummies Questions & Answers
Using dd or similar tools to recover data from 2 damaged cdroms, I need a way to then combine the 2 files, 1 from each cd, and make a good file: this all result from finding that certain cd's tops scratch easily even when using the "proper" cd markers, hence making the file useless, however the... (1 Reply)
Discussion started by: saint65
1 Replies
6. UNIX for Dummies Questions & Answers
Hi Experts,
by mistake i deleted some files that are very important to the project.
is there any way that i can recover those files,there is no backup for that but the details of the file we know.
This will be a great help.
Thanks (5 Replies)
Discussion started by: namishtiwari
5 Replies
7. UNIX for Dummies Questions & Answers
Hi Guys
I accidently deleted a directory( and the files in it) in unix using 'rm -rf' :)
Is there any procedure/script/command to recover the same?
Your help is highly apperciated
-thanks
Subramanya (1 Reply)
Discussion started by: sgbhat
1 Replies
8. Shell Programming and Scripting
Hi,
By mistake, executed the following command :
rm -rf *
and ALL files got deleted.
But I need to get back these files as they are very very important.
Please help me how to recover this file. Its Urgent for me please.
Thanks in advance. (6 Replies)
Discussion started by: unx100
6 Replies