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 |
some commands check that the password is input from the terminal for security reasons. Try 'expect' to fool them..
|
hello there. the following might work for mount:
Code:
mount -t cifs //other_computer/remote_dir /my_computer/local_dir/ -p - < prompt_file Code:
cat promptfile | mount -t cifs //other_computer/remote_dir /my_computer/local_dir/ -p - |
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" Code:
cat some_file | grep foo |
Quote:
Code:
[ $(cat some_file | grep foo >/dev/null; echo $?) -eq 0 ] && echo "contains foo" || echo "does not contain foo" Code:
cat some_file | grep foo && echo "contains foo" || echo "does not contain foo" |
konsolebox,
Thanks for that, that's exactly what I was looking for :) Thanks for your help, I'm still pretty new to shell scripting :) |
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 |
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 :p |
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.
|
Quote:
Quote:
by the time i went to linux, i was also stunned by the great powers of bash. Quote:
Quote:
Edit: it really feels great to hear happy comments from the people you helped. |
Quote:
|
Thanks guys. Will do
|
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.
|
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.
|
What does it do better than 'for' in bash, by the way?
|
All times are GMT -5. The time now is 11:35 PM. |