running Bash file
Moderator: General Moderators
running Bash file
I'm sure that there is a really obvious answer, but as a Linux newbie, it's getting very frustrating. (I come from a windows background, and am therefore more used to batch files)
Essentially I have a process to run, that needs to be run multiple times, against multiple files. I have written a bash script to try and achieve this. It looks like:
[text]
#!/bin/bash
pxsqldump -d mysql -f /mnt/abc_xp/DB/AttachGrp.DB > /mnt/abc_xp/sql3/AttachGrp.sql;
pxsqldump -d mysql -f /mnt/abc_xp/DB/Attachment.DB > /mnt/abc_xp/sql3/Attachment.sql;
pxsqldump -d mysql -f /mnt/abc_xp/DB/AttachSrch.DB > /mnt/abc_xp/sql3/AttachSrch.sql;
. . .
[/text]
Basically it converts the .DB file to a .sql file. I have a copy of Ubuntu running in Virtualbox on my Windows XP machine. I use a shared folder so that the .DB files are on my windows machine, but are showing in Linux at /mnt/abc_xp/DB/
When I double click the file (bash.sh) in Linux it asks if I want to run it in the terminal, or display it etc.
I click run in terminal.
The terminal window opens and closes, but nothing happens.
If I paste the lines individually into a terminal window, they work fine.
I'm sure there must be a simple solution, but so far, I just can't find it.
Essentially I have a process to run, that needs to be run multiple times, against multiple files. I have written a bash script to try and achieve this. It looks like:
[text]
#!/bin/bash
pxsqldump -d mysql -f /mnt/abc_xp/DB/AttachGrp.DB > /mnt/abc_xp/sql3/AttachGrp.sql;
pxsqldump -d mysql -f /mnt/abc_xp/DB/Attachment.DB > /mnt/abc_xp/sql3/Attachment.sql;
pxsqldump -d mysql -f /mnt/abc_xp/DB/AttachSrch.DB > /mnt/abc_xp/sql3/AttachSrch.sql;
. . .
[/text]
Basically it converts the .DB file to a .sql file. I have a copy of Ubuntu running in Virtualbox on my Windows XP machine. I use a shared folder so that the .DB files are on my windows machine, but are showing in Linux at /mnt/abc_xp/DB/
When I double click the file (bash.sh) in Linux it asks if I want to run it in the terminal, or display it etc.
I click run in terminal.
The terminal window opens and closes, but nothing happens.
If I paste the lines individually into a terminal window, they work fine.
I'm sure there must be a simple solution, but so far, I just can't find it.
Re: running Bash file
Did you give your script execute permissions?
Re: running Bash file
I did yes.
sudo chmod +x bash.sh
sudo chmod +x bash.sh
Re: running Bash file
0. what happens when you run this script from the terminal (manually - i.e. ./bash.sh)?
1. what's the user that run this script?
2. is PATH set right for that user/script? ( or use absolute paths to solve this)
1. what's the user that run this script?
2. is PATH set right for that user/script? ( or use absolute paths to solve this)
There are 10 types of people in this world, those who understand binary and those who don't
Re: running Bash file
1. If I navigate to that folder e.g.
[text]
$ cd /mnt/abc_xp
[/text]
then try to execute the file
[text]
$ bash.sh
[/text]
I get "command not found"
2. As far as I know there is only one user, which is the user that was set up when I installed Linux
3. I've checked the paths, and the files are all where I say they should be, and I have looked in /bin and there is a file called bash
[text]
$ cd /mnt/abc_xp
[/text]
then try to execute the file
[text]
$ bash.sh
[/text]
I get "command not found"
2. As far as I know there is only one user, which is the user that was set up when I installed Linux
3. I've checked the paths, and the files are all where I say they should be, and I have looked in /bin and there is a file called bash
Re: running Bash file
It should be either:
or
because /mnt/abc_xp is not in the PATH.
will return the current user.
Code: Select all
/path/to/bash.shCode: Select all
cd /mnt/abc_xp
./bash.shCode: Select all
whoamiThere are 10 types of people in this world, those who understand binary and those who don't
Re: running Bash file
If I type that
and press enter, and then I type
and press enter, I get
[text]
bash:/ .bash.sh: /bin/bash^M: bad interpreter: No Such file or directory
[/text]
the result of
is "ian"
Code: Select all
cd /mnt/abc_xp
Code: Select all
./bash.sh
[text]
bash:/ .bash.sh: /bin/bash^M: bad interpreter: No Such file or directory
[/text]
the result of
Code: Select all
whoami
Re: running Bash file
Code: Select all
which bashThere are 10 types of people in this world, those who understand binary and those who don't
Re: running Bash file
that gives me /bin/bash
Re: running Bash file
Rewrite the first line (the so called shebang line) - it contains a ^M special char at its end. Use Linux text editor to do this (I suppose it was added by a Windows editor).
There are 10 types of people in this world, those who understand binary and those who don't
Re: running Bash file
Ah ha. that has done it. I now have a load of data scrolling across the screen (not what I wanted, but that's a problem with the files I'm working on that I knew about anyway).
Here's me thinking that a plain text file would be a plain text file, wherever, apparently not.
cheers,
Here's me thinking that a plain text file would be a plain text file, wherever, apparently not.
cheers,
Re: running Bash file
I wouldn't name a script file "bash".anything
Re: running Bash file
I would have said the same, if it had been named "bash", but not "bash.sh"Doug G wrote:I wouldn't name a script file "bash".anything
There are 10 types of people in this world, those who understand binary and those who don't
Re: running Bash file
as a side note, probably you could use a shorter script:
Code: Select all
cd /mnt/abc_xp/ && for file in DB/*.DB; do pxsqldump -d mysql -f "${file}" > "sql3/$(basename "${file%DB}sql")"; done
Re: running Bash file
cheers, that was my job for today, so you've just saved me a few hours work.