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.

http://tldp.org/howto/bash-prog-intro-howto-7.html


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -