im trying to call the following within a bash script:
`history -a current_history`
it is supposed to create the file with the commands executed this session.
Works perfectly fine in a shell enviroment
Does not work within a bash script
What am i doing wrong?
Related
I'm using Lua script with ngnix to generate ISO file.
Lua script is parsing request and it should pass it to genisoimage command.
I've tried with:
local pack_cmd = "genisoimage -V" .. some_other_name
os.execute(pack_cmd)
Command is not successfully executed and as return code I get 3328. I've
tried with absoulte path (/usr/bin/genisoimage and /bin/genisoimage) but
it's not working.
I've tried simple workaround - Execute genisoimage command inside bash script
and in Lua script run it like this:
local pack_cmd = "bash /absoulte/path/script.sh " .. some_other_name
os.execute(pack_cmd)
Still not working and getting same exit code. Also tried to catch what's wrong but it look likes command genisoimage is never executed.
local pack_cmd = "bash /absoulte/path/script.sh " .. some_other_name .." >> error.log"
os.execute(pack_cmd)
Version with handles is not working as well
local handle = io.popen(pack_cmd)
local result = handle:read("*a")
handle:close()
If I execute pack_cmd string manually everything works OK. Executing bash script is also working.
The problem was with permissions for www-data user.
I have a script in which I connect as sysdba and run a query.The script works perfectly fine when I run it standalone by sh command.But when I run the script from a cronjob the script runs but the sql part is omitted .
My script is like
echo "before connection"
sqlplus / as sysdba << EOF
Select * from dual
EOF
It works perfectly fine when I run by:
sh script_name.sh
But When I run by a cronjob the connection part is omitted only line which I get in my logs in "before connection"
What could be the solution of this problem?
Perhaps you get the error sqlplus not found. When run from crontab.
You have to export your PATH variable in the script explicitly. Else, load the .profile itself, if needed. Because, your crontab just executes the script, without defining the variables that you had in your .profile.
Add this to your script, to always load your .profile
. $HOME/.profile
OR
. ~/.profile
If you are running on UNIX (UNIX-like) systems, shebang is mandatory. Have you tried shebang on the first line ? (bash is the shell of choice in my systems)
#!/bin/bash
More explanation here.
I have a bash script .sh which needs to be executed as a Target Simulator in Eclipse. The problem is, if I run the script with sh run.sh command in terminal, it throws Bad Substitution error. But it works perfectly with bash run.sh. Apparently, Eclipse run it with sh command cause it gives the same error in console. But how can I make Eclipse to run the script with bash instead?
I'm on Ubuntu 13.10.
bash and sh aren't the same shell. There are many constructs valid in bash that are not understood by sh.
Have you provided a correct sheebang as the first line of your script?
#!/bin/bash
If so -- and if Eclipse insist on running script with sh, you still have the option of wrap your script in a heredoc and pass it to bash explicitly:
sh$ cat run.sh
bash << EOF
#
# Here is your bash script
#
EOF
This is mostly a hack until you find how to instruct Eclipse of using the right shell. I'm sure there is a way!
I am running a shell script by which we are scheduling a task using at command. But it schedules the at task but its not running the same beacuse its using shell /sbin/nologin when we are calling it from php code. It works fine if we run it from terminal.
You should check the "$PATH" env variable. When you are logged in from terminal the shell has initialized it's search path via .bashrc etc. "cron" or "at" jobs don't do that.
So try to log the environment variables to a file in your 'at' jobs and check if it is set up right.
i want to execute some commands through terminal. I have on script for executing commands.Some commands are working but when trying to change directory its not changing. There is no error while executing that script.The script which i made is executable and is mention below:
make clean
make
cd /home/user
save this as script.sh and make it executable
Current working directory is a process property. Each process has independent value for its working directory. Your script works correctly: it changes the current working directory of the shell process that executes it.
If you want your interactive shell to change working directory you have to instruct it. You can do it by "sourcing" your script into your interactive shell. "Sourcing" means reading the script and executing the commands by the shell that sources it. This is opposed to "executing" the script, where a separate shell process is started and executes the script contents.
You can source a script using source or . commands. Like this:
source script.sh
or this:
. script.sh