View previous topic :: View next topic |
Author |
Message |
Lemma Guru
Joined: 19 Apr 2002 Posts: 416 Location: Uppsala, Sweden
|
Posted: Thu Jan 09, 2003 10:52 am Post subject: Bash for backing up remote computers... |
|
|
Hi.
I am a bash-newbie and wish to make a a script that shall have the following function: Code: | Load a few variables from a separate file with name, username and password. Then it shall mount a catalog using smbfs (thus the username&passwd) ,copy everything to a local directory and unmount. This shall be done in an loop (while - do?) until the name loaded from the file reads "end" or similar.
The file with the userinfo shall have one user per line, username may sometimes be empty (with w9x it can be so, but not with the winiNT-series and I will use both). |
This will be used to back up a number of computers at my institution, right now we have no backup
Are the any sites where I can learn bash? I have been looking for a bash-howto or similar, but to my avail... _________________ Always make it as simple as possible, but no simpler
/Einstein |
|
Back to top |
|
|
Naan Yaar Bodhisattva
Joined: 27 Jun 2002 Posts: 1549
|
Posted: Thu Jan 09, 2003 1:29 pm Post subject: Re: Bash for backing up remote computers... |
|
|
Here.
Lemma wrote: | ...
Are the any sites where I can learn bash? I have been looking for a bash-howto or similar, but to my avail... |
|
|
Back to top |
|
|
Lemma Guru
Joined: 19 Apr 2002 Posts: 416 Location: Uppsala, Sweden
|
Posted: Thu Jan 09, 2003 5:51 pm Post subject: |
|
|
Ok, one can use awk to select what is of interest in a file (with everly line like name:passwd:path),doing Code: | PASSWORD_FILE=/etc/passwd
name=$(awk 'BEGIN{FS=":"}{print $1}' < "$PASSWORD_FILE" ) | That gives me all the names in one file, and I can step through name with a for name in {do [...] done}, but how do I step through it not using for? How to use the index that name is? passwd[n] for getting the n:th password does not work _________________ Always make it as simple as possible, but no simpler
/Einstein |
|
Back to top |
|
|
Lemma Guru
Joined: 19 Apr 2002 Posts: 416 Location: Uppsala, Sweden
|
Posted: Thu Jan 09, 2003 5:55 pm Post subject: |
|
|
Quote: | How to use the index that name is? passwd[n] for getting the n:th password does not work icon_sad.gif | I should have written name[n] for getting the n:th name does not work. _________________ Always make it as simple as possible, but no simpler
/Einstein |
|
Back to top |
|
|
Lemma Guru
Joined: 19 Apr 2002 Posts: 416 Location: Uppsala, Sweden
|
Posted: Thu Jan 09, 2003 7:45 pm Post subject: |
|
|
Made it work, thx for the link _________________ Always make it as simple as possible, but no simpler
/Einstein |
|
Back to top |
|
|
Lemma Guru
Joined: 19 Apr 2002 Posts: 416 Location: Uppsala, Sweden
|
Posted: Fri Jan 10, 2003 7:59 am Post subject: |
|
|
Hi again.
Trying to get a "not so ugly " way of getting it to work. Code: | PASSWORD_FILE=/home/daniel/backup.who
IFS=":"
cat $PASSWORD_FILE | while read LINE
do
set -- $( echo $LINE )
# $1 = name
# $2 = username
# $3 = passwd
# $4 = path
# $* = line
done | The problem is that $1 gives the whole line and $n {n>1} gives null (or unassigned, can't tell the difference . Any suggestions? _________________ Always make it as simple as possible, but no simpler
/Einstein |
|
Back to top |
|
|
jukka Apprentice
Joined: 06 Jun 2002 Posts: 249 Location: Zurich, Switzerland
|
Posted: Fri Jan 10, 2003 8:40 am Post subject: |
|
|
Lemma wrote: | Any suggestions? |
what about something like this: Code: | IFS=':'
while read -a line; do
# now you can access all elements of the current line as line[n]
# for instance:
for (( i=0; i<${#line[@]}; ++i )); do
echo "line[$i]: ${line[$i]}"
done
done </etc/passwd |
hth, jukka |
|
Back to top |
|
|
Lemma Guru
Joined: 19 Apr 2002 Posts: 416 Location: Uppsala, Sweden
|
Posted: Fri Jan 10, 2003 10:09 am Post subject: |
|
|
Great !!!
Now I can get some work done!
Thx! _________________ Always make it as simple as possible, but no simpler
/Einstein |
|
Back to top |
|
|
|