You are not logged in.

#1 2006-10-29 23:56:57

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

bash scripting help..

why o why does this not work... i have tried a million different types of combinations..

  1 #!/bin/bash
  2 
  3 tar --create --verbose --file=etc.tar $ETC_FILES
  4 ETC_FILES=('/etc/rc.conf /etc/pacman.conf')
  5 echo $ETC_FILES
  6             exit 0
  7             

[root@Estergon ~]# ./test.sh 
tar: Cowardly refusing to create an empty archive
Try `tar --help' or `tar --usage' for more information.
/etc/rc.conf /etc/pacman.conf

The ultimate Archlinux release name: "I am your father"

Offline

#2 2006-10-29 23:58:55

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: bash scripting help..

you ahve to declare ETC_FILES before using it

ETC_FILES=('/etc/rc.conf /etc/pacman.conf') 
tar --create --verbose --file=etc.tar $ETC_FILES

Offline

#3 2006-10-30 00:03:47

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: bash scripting help..

Yup. It works fine when you put those lines in the right order.

Offline

#4 2006-10-30 00:20:05

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: bash scripting help..

thx.. stupid mistake..

can you help me with this one?

USER_SET=('$HOME/.vim/ $HOME/.vimrc $HOME/.xinitrc')
 27     tar --create --verbose --file=user_set.tar $USER_SET
 28 exit 0

[root@Estergon ~]# ./test.sh 
tar: "$HOME/.vim/": Cannot stat: No such file or directory
tar: "$HOME/.vimrc": Cannot stat: No such file or directory
tar: "$HOME/.xinitrc": Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
[root@Estergon ~]# 

The ultimate Archlinux release name: "I am your father"

Offline

#5 2006-10-30 00:31:37

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: bash scripting help..

USER_SET=('~/.vim/ ~/.vimrc ~/.xinitrc')
27     tar --create --verbose --file=user_set.tar $USER_SET
28 exit 0

Offline

#6 2006-10-30 00:32:22

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: bash scripting help..

~ is an alias for home directory

Offline

#7 2006-10-30 00:36:08

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: bash scripting help..

thx, but didnt work:

tar: ~/.vim: Cannot stat: No such file or directory
tar: ~/.vimrc: Cannot stat: No such file or directory
tar: ~/.xinitrc: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

[root@Estergon ~]# cat .vimrc
nmap mm :make <CR>
set number
set expandtab
set tabstop=4
set shiftwidth=4
set autoindent
colorscheme elflord

[root@Estergon ~]#


The ultimate Archlinux release name: "I am your father"

Offline

#8 2006-10-30 00:39:45

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: bash scripting help..

jinn wrote:

thx.. stupid mistake..

can you help me with this one?

USER_SET=('$HOME/.vim/ $HOME/.vimrc $HOME/.xinitrc')
 27     tar --create --verbose --file=user_set.tar $USER_SET
 28 exit 0

[root@Estergon ~]# ./test.sh 
tar: "$HOME/.vim/": Cannot stat: No such file or directory
tar: "$HOME/.vimrc": Cannot stat: No such file or directory
tar: "$HOME/.xinitrc": Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
[root@Estergon ~]# 

Use double quotes instead of single ones:
USER_SET=("$HOME/.vim/ $HOME/.vimrc $HOME/.xinitrc")

Offline

#9 2006-10-30 00:45:22

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: bash scripting help..

$HOME="/home/framki"
USER_SET="$HOME/.vim $HOME/.vimrc $HOME/.xinitrc"

this way i think it works

Offline

#10 2006-10-30 00:46:33

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: bash scripting help..

what happened before is that u used single quotes

USER_SET=('$HOME/.vim/ $HOME/.vimrc $HOME/.xinitrc') 

single quotes are literal representation, without variable substitution

Offline

#11 2006-10-30 00:49:17

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: bash scripting help..

this means that tar was trying to open a directory actually called $HOME, without making the substitution from $HOME to whatever you set before.

On the other hand, i have no idea why with ~ it didn't work.

Offline

#12 2006-10-30 00:49:59

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: bash scripting help..

double quotes worked

thx


The ultimate Archlinux release name: "I am your father"

Offline

#13 2006-10-30 00:59:31

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: bash scripting help..

Now comes the tricky part..

how can i scp the created tar files automatically? or ftp/any kind of transfer..

I would either like it to be uploaded to my googlepages, or my uni account with scp.

thx again


The ultimate Archlinux release name: "I am your father"

Offline

#14 2006-10-30 03:07:28

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: bash scripting help..

Look into copying ssh keys to the remote server and logging in with remote keys instead of passwords... makes automating that type of thing much easier.

http://wiki.archlinux.org/index.php/Using_SSH_Keys
http://www.debian-administration.org/articles/152

Offline

#15 2006-10-30 07:43:00

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: bash scripting help..

thx alot!


The ultimate Archlinux release name: "I am your father"

Offline

#16 2006-10-30 09:58:18

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: bash scripting help..

you are welcome... to open source. Share your knowledge wink

Offline

#17 2006-10-30 21:09:45

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: bash scripting help..

Another question,

I want to import all variables from one script into another.. how can i do that?

Figured it should be with source.. but cant make it to work. Can anyone show a working example?


The ultimate Archlinux release name: "I am your father"

Offline

#18 2006-10-30 21:13:12

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: bash scripting help..

maybe you can do a call or something similar

Offline

#19 2006-10-30 21:19:21

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: bash scripting help..

Use the export command.

NOTE: Once the variable is in the environment, it can be accessed by the child processes. Note that the parent process will not inherit any variables from the children. This is very dangerous. In scripts, if you are setting variables to be used locally in the script, you won't have to export. But if you wish for those processes your script calls, ie, another script, then you will have to export.

export TEMPVAR=something

Offline

#20 2006-10-30 21:55:54

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: bash scripting help..

i also think of the possibily of having a list of wiht the variables names:
export MY_VAR_LIST="VAR1 VAR2 VAR3"

example:

#!/bin/bash

echo A=$A
echo B=$B
if [ "$A" != "" ]; then
        echo "We got A and B set!";
        exit;
else
        echo "A and B are empty";
fi
sleep 1

A="1";
B="2";
VARS="A B";

PREFIX=""
for i in $VARS; do
        PREFIX="$PREFIX$i="$(eval echo $$i)" "
done
eval "$PREFIX ./test"

this example checks A and B. if it is not set calls itself passing to itself with the variables filled. then it stops.

Offline

#21 2006-10-30 21:59:36

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: bash scripting help..

in advance to export, with the example below (check the previous page) you can have control of which variables go to each process without having to create global variables.

in disatvange, you are responsible of escaping doble qutoes: "

Offline

#22 2006-10-30 22:02:05

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: bash scripting help..

The idea is that in one file, I declare variables, which include the packages i would like to install if I reinstall, and a main file which can import these variables and run the script, installing the packages.

I could simply put all variables in one file, but that would be ugly and not structured.

script main: restore.sh
script variables: packages.sh


The ultimate Archlinux release name: "I am your father"

Offline

#23 2006-10-30 22:12:21

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: bash scripting help..

you could just source in a text document that has

--------------------------------------

# installlist.txt
# Start list of packages to install
pacman -S irssi
pacman -S openssh
pacman -S kde
blah blah blah...... you get the idea
----------------------------------------------------------

In your restore script , call the file, and wherever you "source" it in, it will run.

source /path/to/installlist.txt

something like that ????

Offline

#24 2006-10-30 23:18:54

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: bash scripting help..

or just have a string in a file:

packages="kde openssh irssi pebrot"

and source that file in, and do:
pacman -S $packages

It'll also be quicker installing them all at once, rather than one by one.

James

Offline

#25 2006-10-31 09:22:15

jinn
Member
From: Gothenburg
Registered: 2005-12-10
Posts: 506

Re: bash scripting help..

Iphitus, that is exactly what i have been trying to do, but source doesnt seem to work ..

Check it out:
restore.sh:

   #!/bin/bash
   source packages.sh
   echo $TEST
   
   exit 0

packages.sh:

 6 TEST="acpid cpufreq biatch"
  7 LAPTOP=('acpid'
  8         'cpufrequtils'
  9         'gnome-power-manager'
 10         'powernowd'
 11         'synaptics')

and running the restore gives nothing:

[root@Estergon scripting]# ./restore.sh 
[root@Estergon scripting]# 

The ultimate Archlinux release name: "I am your father"

Offline

Board footer

Powered by FluxBB