Use number of downloaded file in wget as variable in bash script
Can I get the number of downloaded files with wget -r and use that as a variable? I want to write a script that runs multiple wget commands in it (using -q so i can control output) and then at the end, add up the number of downloaded files and echo that to the user. Is this possible?
To build on Jed’s suggestion and take it the rest of the way, you could do something like this:
MY_VARIABLE=$(wget -r http://foo 2>&1 | grep -c 'saved')
Or, if you wanted to go a touch more complicated, but more reliable and robust, you could pull out the download count given as the summary by wget:
MY_VARIABLE=$(wget -r -nv http://foo 2>&1 | awk '/^Downloaded:/ {print $2}')
Check more discussion of this question.
Related posts:
Leave a comment
Recent Posts
- Cron expression that runs every 5 minutes from 1:30 am – 6:00 am [duplicate]
- Understanding redundant power supplies
- Is there a way for administrators to disable users from installing Firefox extensions?
- Is there research material on NTP accuracy available?
- How to create a limited “domain admin” that does not have access to domain controllers?
Tags
active-directory
amazon-ec2
apache
apache2
backup
bash
centos
cisco
command-line
debian
dns
email
exchange
firewall
iis
iis7
iptables
linux
macosx
monitoring
mysql
networking
nginx
performance
permissions
php
postfix
raid
security
sql-server
sql-server-2005
sql-server-2008
ssh
ssl
ubuntu
unix
virtualization
vpn
webserver
windows
windows-7
windows-server-2003
windows-server-2008
windows-server-2008-r2
windows-xp





