shell - Bash Script: How to use variables from list -
i trying write script report last time file updated in folder. folders created everyday example: /home/user/todaysdate. inside todaysdate folder exsist created when somethng created. example have fol1 fol2 fol3. trying script login each folder , display time of last file created.
#!/bin/bash folder=`date +%y%m%d` ssh -q server "cd /home/user/$folder/ ; bash -c "ls -la | uniq" > list.txt
this create list of different folders made. need ssh each folder stuck. output of list.txt be: fol1 fol2 fol3
ssh -q server "bash -c \"ls -ltr /home/user/$folder/<need list variable here> | tail -1\"" awk '{print $8}
the above command gives me time. believe need while loop ssh server , variables created in list.txt can't working on. help?
if list.txt space separated (eg "fol1 fol2 fol3") try bash for/in loop:
for folder in $(cat list.txt); echo $folder; done
if list.txt newline separated try bash while loop:
cat list.txt | while read folder; echo $folder; done
see page more information bash loops.
Comments
Post a Comment