Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Debian User (http://www.linux-archive.org/debian-user/)
-   -   bash related question, adding variable into path (http://www.linux-archive.org/debian-user/675652-bash-related-question-adding-variable-into-path.html)

Umarzuki Mochlis 06-22-2012 04:34 AM

bash related question, adding variable into path
 
below scripts stuck when i added id variable to a path.

this script supposed to copy message files (from 18-22 june) from a
zimbra store/mailbox of a user and copied it into /tmp

#!/bin/bash
echo "Username? then [ENTER]:"
read username
id=`/opt/zimbra/bin/mysql -e 'use zimbra;select id,comment from
mailbox;' | grep $username | cut -f 1`
mkdir /tmp/$username 2>/dev/null
for i in `egrep '(1[8-9]|2[0-2]) Jun 2012'
/opt/zimbra/store/0/$id/msg/0/* | cut -d : -f 1 | uniq`
do
cp $i /tmp/$username
done

there must be something that i had missed...

thanks
--
Regards,

Umarzuki Mochlis
http://debmal.my


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/CAHW9mbw+hdiphHS+G_=4zTA8zDaGy9AfvmRUaQ4TVvRM5+kdA g@mail.gmail.com

Camaleón 06-22-2012 03:41 PM

bash related question, adding variable into path
 
On Fri, 22 Jun 2012 12:34:40 +0800, Umarzuki Mochlis wrote:

> below scripts stuck when i added id variable to a path.
>
> this script supposed to copy message files (from 18-22 june) from a
> zimbra store/mailbox of a user and copied it into /tmp
>
> #!/bin/bash
> echo "Username? then [ENTER]:"
> read username
> id=`/opt/zimbra/bin/mysql -e 'use zimbra;select id,comment from mailbox;' | grep $username | cut -f 1` mkdir /tmp/$username 2>/dev/null
> for i in `egrep '(1[8-9]|2[0-2]) Jun 2012'
> /opt/zimbra/store/0/$id/msg/0/* | cut -d : -f 1 | uniq` do
> cp $i /tmp/$username
> done
>
> there must be something that i had missed...

Print/echo the $id variable to check for its current value as seen in
runtime by your script :-?

Greetings,

--
Camaleón


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/js23nl$5le$12@dough.gmane.org

Umarzuki Mochlis 06-23-2012 04:14 AM

bash related question, adding variable into path
 
2012/6/22 Camaleón <noelamac@gmail.com>:
> On Fri, 22 Jun 2012 12:34:40 +0800, Umarzuki Mochlis wrote:

>> #!/bin/bash
>> echo "Username? then [ENTER]:"
>> read username
>> id=`/opt/zimbra/bin/mysql -e 'use zimbra;select id,comment from mailbox;' | grep $username | cut -f 1` mkdir /tmp/$username 2>/dev/null
>> for i in `egrep '(1[8-9]|2[0-2]) Jun 2012'
>> /opt/zimbra/store/0/$id/msg/0/* | cut -d : -f 1 | uniq` do
>> cp $i /tmp/$username
>> done
>>
>> there must be something that i had missed...
>
> Print/echo the $id variable to check for its current value as seen in
> runtime by your script :-?


i had checked with echo that $id indeed output a id and running

if i put the id value exactly as output of "/opt/zimbra/bin/mysql -e
'use zimbra;select id,comment from mailbox;' | grep $username | cut -f
1", it worked

what else could should i look for?
--
Regards,

Umarzuki Mochlis
http://debmal.my


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: CAHW9mby7DTGGTUyVeOAetAgmvSPgyQaYVpVZ52NNFkNmB7mS7 Q@mail.gmail.com">http://lists.debian.org/CAHW9mby7DTGGTUyVeOAetAgmvSPgyQaYVpVZ52NNFkNmB7mS7 Q@mail.gmail.com

Keith McKenzie 06-23-2012 08:29 AM

bash related question, adding variable into path
 
I think maybe put ; after the first command before issuing the second
command mkdir

id=`/opt/zimbra/bin/mysql -e 'use zimbra;select id,comment from
mailbox;' | grep $username | cut -f 1` ; mkdir /tmp/$username
2>/dev/null

&/or, possibly you need to escape your statement

id=`/opt/zimbra/bin/mysql -e 'use zimbra;select id,comment from
mailbox;' | grep $username | cut -f 1` ; mkdir /tmp/$username
2>/dev/null

--
Sent from FOSS (Free Open Source Software)
Debian GNU/Linux


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: CAL36VGn3jAW9cumNdq0YYcqwVBdVLKuzYK1E65z6nDaLtEvXt A@mail.gmail.com">http://lists.debian.org/CAL36VGn3jAW9cumNdq0YYcqwVBdVLKuzYK1E65z6nDaLtEvXt A@mail.gmail.com

Umarzuki Mochlis 06-23-2012 09:46 AM

bash related question, adding variable into path
 
2012/6/23 Keith McKenzie <km3952@gmail.com>:
> I think maybe put ; after the first command before issuing the second
> command mkdir
>
> id=`/opt/zimbra/bin/mysql -e 'use zimbra;select id,comment from
> mailbox;' | grep $username | cut -f 1` ; mkdir /tmp/$username
> 2>/dev/null
>
> &/or, possibly you need to escape your statement
>
> id=`/opt/zimbra/bin/mysql -e 'use zimbra;select id,comment from
> mailbox;' | grep $username | cut -f 1` ; mkdir /tmp/$username
> 2>/dev/null

thanks
but on my code it is actually on a newline

--
Regards,

Umarzuki Mochlis
http://debmal.my


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/CAHW9mbwzOdkhhfONhVXpTomjzbz73TkM6dOWC82zeHq=8zsCP w@mail.gmail.com

Camaleón 06-23-2012 10:05 AM

bash related question, adding variable into path
 
On Sat, 23 Jun 2012 12:14:39 +0800, Umarzuki Mochlis wrote:

> 2012/6/22 Camaleón <noelamac@gmail.com>:
>> On Fri, 22 Jun 2012 12:34:40 +0800, Umarzuki Mochlis wrote:
>
>>> #!/bin/bash
>>> echo "Username? then [ENTER]:"
>>> read username
>>> id=`/opt/zimbra/bin/mysql -e 'use zimbra;select id,comment from mailbox;' | grep $username | cut -f 1`
>>> mkdir /tmp/$username 2>/dev/null

Put an echo here.

>>> for i in `egrep '(1[8-9]|2[0-2]) Jun 2012'
>>> /opt/zimbra/store/0/$id/msg/0/* | cut -d : -f 1 | uniq`

And another flag here.

>>> do
>>> cp $i /tmp/$username

And just in case, also print the value of $username to track all the
variables used in the script.

>>> done
>>>
>>> there must be something that i had missed...
>>
>> Print/echo the $id variable to check for its current value as seen in
>> runtime by your script :-?
>
>
> i had checked with echo that $id indeed output a id and running

Care to send the output of the script when you run it once you added the
echo lines? :-)

> if i put the id value exactly as output of "/opt/zimbra/bin/mysql -e
> 'use zimbra;select id,comment from mailbox;' | grep $username | cut -f
> 1", it worked

So you mean the whole script works okay.

> what else could should i look for?

I don't know... need more data.

Greetings,

--
Camaleón


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: http://lists.debian.org/js44dm$io1$5@dough.gmane.org

rjc 06-23-2012 10:24 AM

bash related question, adding variable into path
 
On Fri, Jun 22, 2012 at 05:34:40AM BST, Umarzuki Mochlis wrote:
> below scripts stuck when i added id variable to a path.
>
> this script supposed to copy message files (from 18-22 june) from a
> zimbra store/mailbox of a user and copied it into /tmp
>
> #!/bin/bash
> echo "Username? then [ENTER]:"
> read username
> id=`/opt/zimbra/bin/mysql -e 'use zimbra;select id,comment from
> mailbox;' | grep $username | cut -f 1`
> mkdir /tmp/$username 2>/dev/null
> for i in `egrep '(1[8-9]|2[0-2]) Jun 2012'
> /opt/zimbra/store/0/$id/msg/0/* | cut -d : -f 1 | uniq`
> do
> cp $i /tmp/$username
> done
>
> there must be something that i had missed...

1. Hard to tell, as you simply pasted the script instead of attaching
an actual fine - the line breaks are wrong I take it. Please simply
attach one next time.
2. Your problem is a bash problem per se as there's nothing bash
specific in your script, you might as well change the hashbang to
#!/bin/sh - it'll save you some resources ;^)
3. Backticks '`' can be tricky to work with, try using $() instead -
they nest better, are cleaner, more readable, and they're POSIX.
4. If you need literal results, quote the command substitution - "$id".
5. Last but not least - debug your script!

Regards,
--
rjc


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20120623102403.GA11376@linuxstuff.pl">http://lists.debian.org/20120623102403.GA11376@linuxstuff.pl


All times are GMT. The time now is 04:28 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.