LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-25-2006, 12:34 AM   #1
swedish_lunacy
LQ Newbie
 
Registered: Jul 2006
Location: New Zealand
Distribution: Fedora 5
Posts: 10

Rep: Reputation: 0
Using BASH redirects and "prompt" files to interact with commands/scripts ??


Hi there,
I am trying to interact with BASH commands/scripts using stdin redirects from a file but it doesn't seem to work on all commands

For example:

rm -Ri /some_dir < prompt_file

Seems to work

But the following mount command which prompts for a password:

mount -t cifs //other_computer/remote_dir /my_computer/local_dir/ < prompt_file

Does not seem to read the prompts from the redirected file. Instead it comes up with a prompt requesting for a password. ( PS I know that I can use the -o password="my_pass" option but I am trying to figure out what's going wrong with the redirects for this, I want to start using BASH scripts and redirects to interact with commands that are called )

Cheers
Nick

Last edited by swedish_lunacy; 07-25-2006 at 12:35 AM.
 
Old 07-25-2006, 02:13 AM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

Rep: Reputation: 68
some commands check that the password is input from the terminal for security reasons. Try 'expect' to fool them..
 
Old 07-25-2006, 04:16 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
hello there. the following might work for mount:

Code:
mount -t cifs //other_computer/remote_dir /my_computer/local_dir/ -p - < prompt_file
OR

Code:
cat promptfile | mount -t cifs //other_computer/remote_dir /my_computer/local_dir/ -p -
edit: what commands do you want to use btw?

Last edited by konsolebox; 07-25-2006 at 04:20 AM.
 
Old 07-25-2006, 04:21 AM   #4
swedish_lunacy
LQ Newbie
 
Registered: Jul 2006
Location: New Zealand
Distribution: Fedora 5
Posts: 10

Original Poster
Rep: Reputation: 0
Raskin: Thanks for that, I will install expect on my system and have a play with it
konsolebox: Thanks, gave it a shot but it didn't seem to work. The man pages for mount show -p as expecting a file descriptor number for a passphrase. Is this something different ?

PS: When writing bash scripts is it always best to use $? to test for the return status of a recently run command or is there another way of gaining acces to a command's return code? ie is there a way to directly test a command's return code in the middle of a conditional statement

Code:
[ ( cat some_file | grep foo ) -eq 0 ] && echo "contains foo" || echo "does not contain foo"
rather than

Code:
cat some_file | grep foo
[ $? -eq 0 ] && echo "contains foo" || echo "does not contain foo"

Last edited by swedish_lunacy; 07-25-2006 at 04:38 AM.
 
Old 07-25-2006, 04:36 AM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by swedish_lunacy
Code:
[ ( cat some_file | grep foo ) -eq 0 ] && echo "contains foo" || echo "does not contain foo"
should be
Code:
[ $(cat some_file | grep foo >/dev/null; echo $?) -eq 0 ] && echo "contains foo" || echo "does not contain foo"
also why not just
Code:
cat some_file | grep foo && echo "contains foo" || echo "does not contain foo"
 
Old 07-25-2006, 04:43 AM   #6
swedish_lunacy
LQ Newbie
 
Registered: Jul 2006
Location: New Zealand
Distribution: Fedora 5
Posts: 10

Original Poster
Rep: Reputation: 0
konsolebox,

Thanks for that, that's exactly what I was looking for

Thanks for your help, I'm still pretty new to shell scripting

 
Old 07-25-2006, 04:48 AM   #7
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
no problem. you can ask me more if you like. bash scripting's fun for me.

here's some good manuals too:

Advance Bash Scripting
http://www.tldp.org/LDP/abs/html/

Bash Guide for Beginners
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
 
Old 07-25-2006, 05:12 AM   #8
swedish_lunacy
LQ Newbie
 
Registered: Jul 2006
Location: New Zealand
Distribution: Fedora 5
Posts: 10

Original Poster
Rep: Reputation: 0
konsolebox,

Thanks for the links.

I can see why you enjoy bash scripting. It seems to me that the possibilities are endless ( once you get your head around the syntax ). I have come from an MS background and I am just stunned at how versatile linux is !

I have only just begun working on my first script. I'm generally pretty good at finding the information I need using a combination of TLDP, man, info, and google, but sometimes I can get pretty stuck on something simple and just need to be pointed in the right direction

If I end up getting stumped on something how can I get a hold of you ? Should I just post on the forum ?

Cheers
 
Old 07-25-2006, 05:25 AM   #9
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

Rep: Reputation: 68
There's no point to try to get answer from some particular forum member. You can always post (preferably after searching). Then members who are reading forum at the moment will try to help you. Yes, and don't forget 'info bash' while reading guides.. Most times man bash is sufficient.
 
Old 07-25-2006, 05:33 AM   #10
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by swedish_lunacy
Thanks for the links.
you're welcome
Quote:
Originally Posted by swedish_lunacy
I have come from an MS background and I am just stunned at how versatile linux is !
me too. before when i was just using ms-dos i loved playing with the batch files. then transferred to win9x then to winnt's cmd.exe. i also make complicated scripts with cmd.exe.

by the time i went to linux, i was also stunned by the great powers of bash.
Quote:
Originally Posted by swedish_lunacy
If I end up getting stumped on something how can I get a hold of you ? Should I just post on the forum ?
just post a topic with bash in its title. like other members i'll just try to help too.
Quote:
Originally Posted by swedish_lunacy
Cheers
cheers too

Edit: it really feels great to hear happy comments from the people you helped.

Last edited by konsolebox; 07-25-2006 at 05:44 AM.
 
Old 07-25-2006, 05:35 AM   #11
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by raskin
Most times man bash is sufficient.
i 2nd the motion
 
Old 07-25-2006, 06:16 AM   #12
swedish_lunacy
LQ Newbie
 
Registered: Jul 2006
Location: New Zealand
Distribution: Fedora 5
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks guys. Will do
 
Old 07-25-2006, 01:20 PM   #13
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
CMD scripting is surprisingly capable, but for times when it's not enough, you may be interested in looking at Cygwin. Once you have become accustomed to the usefulness of bash (and the other GNU command line tools), it is a real boon to have them available on Windows as well.
 
Old 07-25-2006, 05:52 PM   #14
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
comparing cmd to bash, cmd has one good command though.. the for loop. i like its token handling. but cmd still lacks many things so overall i'll still go for bash.
 
Old 07-25-2006, 06:10 PM   #15
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,899

Rep: Reputation: 68
What does it do better than 'for' in bash, by the way?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"clear" and "reset" bash commands broken AviJacobson Linux - General 6 07-03-2006 07:28 AM
"clear" and "reset" bash commands broken AviJacobson Linux - Software 1 06-29-2006 03:31 PM
.kde/Autostart bash scripts "file not found" Nice-n-Slow Linux - Software 1 07-02-2004 06:25 PM


All times are GMT -5. The time now is 04:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration