small bash script copy one file to list of directories on file
Hi i want write script to copy robots.txt file to all of the web_root directory this should be only file if not available on root directories.
there is more than 50 web_root directories. and need to send a mail if not available ? #!/bin/bash file=/home/shanaka/robots.txt for dir in /home/deploy/*/public_html do cp "$file" "$dir" done i have write above that, it is only can copy files to all directory, but not check whether available or not, sending mail, can you help me to do this ? |
maybe something like this:
Code:
#!/bin/bash |
thanks friend it was really help,but i want to send mail if robots.txt file not available on location, which should be with include directory location which is not available. but now all the files are copping before check the file availability, therefore mail is not working.
i have edited your script. but it is not working giving error. can you help me on this ? #!/bin/bash file=/home/shanaka/robots.txt for dir in /home/shanaka/test/*/public_html if [ ! -e $dir/robots.txt ] then mail -s "404: file not found " lahirushana@gmail.com do cp "$file" "$dir" fi done |
You need the "do" after the for statement, not before the cp command.
|
then it is not sending mail, bcz it is coping file before check the file availability
|
HI friends wrote something like below, thanks for helping me alot,
Quote:
|
I do not really understand what do you need, but here are some tips:
Code:
filename=robots.txt |
Quote:
thanks you very much friends, what i realy want is check robots.txt file in all web root, if it is there then, theck whether it is disallow or not. if it is not, i need to copy robots.txt file to not available web directories. this is my result for previous code. /home/shanaka/test1/project1/public_html is not same /home/shanaka/test1/project2/public_html is not same /home/shanaka/test1/project3/public_html is not same /home/shanaka/test1/project4/public_html is not same /home/shanaka/test1/project5/public_html is not same so here only "/home/shanaka/test1/project1/public_html is not same directory file only differet, but it is showing all the directory as wrong, there for i want to grep different one only. and copy file to those directories. |
Hi,
Im getting below error please help me ./robo.sh: line 12: [: : integer expression expected ./robo.sh: line 12: [: : integer expression expected ./robo.sh: line 12: [: : integer expression expected ./robo.sh: line 12: [: : integer expression expected |
$result is probably not a number (what are you expecting it to be ?).
please change the first line of your script to #!/bin/bash -x and show us the result. |
Quote:
#!/bin/bash file=/home/shanaka/robots.txt for dir in /home/shanaka/test1/*/public_html do if [ ! -e $dir/robots.txt ] then ls -l /home/shanaka/test1/*/public_html/ | mail -s "404: file not found" lahirushanaka@gmail.com cp "$file" "$dir" else result=$(diff $file $dir/robots.txt > /dev/null;) if [ "$?" -ne 0 ] then echo $dir is not same cp "$file" "$dir" fi fi done |
All times are GMT -5. The time now is 06:45 PM. |