Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Bash for backing up remote computers...
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Lemma
Guru
Guru


Joined: 19 Apr 2002
Posts: 416
Location: Uppsala, Sweden

PostPosted: Thu Jan 09, 2003 10:52 am    Post subject: Bash for backing up remote computers... Reply with quote

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 :oops:

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
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Thu Jan 09, 2003 1:29 pm    Post subject: Re: Bash for backing up remote computers... Reply with quote

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
View user's profile Send private message
Lemma
Guru
Guru


Joined: 19 Apr 2002
Posts: 416
Location: Uppsala, Sweden

PostPosted: Thu Jan 09, 2003 5:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
Lemma
Guru
Guru


Joined: 19 Apr 2002
Posts: 416
Location: Uppsala, Sweden

PostPosted: Thu Jan 09, 2003 5:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
Lemma
Guru
Guru


Joined: 19 Apr 2002
Posts: 416
Location: Uppsala, Sweden

PostPosted: Thu Jan 09, 2003 7:45 pm    Post subject: Reply with quote

Made it work, thx for the link :-)
_________________
Always make it as simple as possible, but no simpler
/Einstein
Back to top
View user's profile Send private message
Lemma
Guru
Guru


Joined: 19 Apr 2002
Posts: 416
Location: Uppsala, Sweden

PostPosted: Fri Jan 10, 2003 7:59 am    Post subject: Reply with quote

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 :oops: . Any suggestions?
_________________
Always make it as simple as possible, but no simpler
/Einstein
Back to top
View user's profile Send private message
jukka
Apprentice
Apprentice


Joined: 06 Jun 2002
Posts: 249
Location: Zurich, Switzerland

PostPosted: Fri Jan 10, 2003 8:40 am    Post subject: Reply with quote

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
View user's profile Send private message
Lemma
Guru
Guru


Joined: 19 Apr 2002
Posts: 416
Location: Uppsala, Sweden

PostPosted: Fri Jan 10, 2003 10:09 am    Post subject: Reply with quote

Great :lol: !!!
Now I can get some work done!
Thx!
_________________
Always make it as simple as possible, but no simpler
/Einstein
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum