Question

I'm writing code to make some wget and get the backup file in some routers.

My first problem is with the variable RT. If I declare only IP on this variable (and add the /config.dat or anything else in wget line) this script will work, otherwise it will say that the "directory was not found."

How can I declare it as it is in the script below?

My second question: I want to say that the output file -O is the IP with the extension .dat for the 2 first IP and for the third it will not have extension just the IP.

Is it possible to do that as I said?

#!/bin/sh
RT="10.0.0.59/config.dat 10.0.0.60/cgi-bin/export_settings.cgi 10.0.0.66/rom-0"
MT="10.0.0.57 10.0.0.58"
L_RT="LOGIN"
P_RT="PASSWORD"

#FUTURE USE WITH TAR
#tmp=$"(mktemp -d)"
#trap -- 'rm -frv -- "$tmp"' EXIT
#cd -- "$tmp"

for bkp_rt in $RT; do
   wget --auth-no-challenge --user=$L_RT --password=P_RT $bkp_rt -O $bkp_rt
done

After updating my script.

#!/bin/bash
RT="10.0.0.59/config.dat 10.0.0.60/cgi-bin/export_settings.cgi 10.0.0.66/rom-0"
MT="10.0.0.57 10.0.0.58"
L_RT="admin"
P_RT="PASSWORD"
L=MT="backup"

#tmp=$"(mktemp -d)"
#trap -- 'rm -frv -- "$tmp"' EXIT
#cd -- "$tmp"

for bkp_rt in $RT; do

wget --auth-no-challenge --user=$L_RT --password=$P_RT \
"$bkp_rt" \
-O "$bkp_rt"
done
Was it helpful?

Solution

You're missing the $ for --password=P_RT.

If you want to use 10.0.0.60/cgi-bin/export_settings.cgi as a filename, you'll have to make sure the 10.0.0.60 and 10.0.0.60/cgi-bin directories exist first.

To fetch the URL with wget, you will probably need to specify the scheme:

for bkp_rt in $RT; do
   mkdir -p "$(dirname "$bkp_rt")"
   wget --auth-no-challenge --user="$L_RT" --password="$P_RT" "$bkp_rt" \
        -O "$bkp_rt"
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top