Using Script to Execute C File in Different Directory - shell

I am new to C, so apologies if this is a naive question. I have been given a script to execute C programs. The first line has the format:
./directory_name program_name program_parameter_1 program_parameter_2
When I execute the script from a different directory I get the following error:
No such file or directory.
When I execute the script from the named directory, I get a different type of error:
directory_name is a directory.
Does someone know what the script file is trying to accomplish?
I have read about commands that change directories through script files, but they don't seem to have this format (i.e. directory name following ./), so I am confused.
Thanks!

If the script is presenting a different behavior depending on the directory you are running it, that means the code inside the file is referencing some dependency that is mapped from a specific location.
Why don't you check the source and learn more about what the script is doing?
Are you confused about "./"? That's how you execute a script, you don't have to worry about what kind of interpreter will process this code, that's defined in the shebang (#!).
You can read more about it here:
http://en.wikibooks.org/wiki/C_Shell_Scripting/Hello

Related

solving Can't open perl script "all_gen_cmf_image": No such file or directory error

i work on image copy move forgery detection field. i downloaded GRIP dataset form https://www.grip.unina.it/, there is some modification needed for the images and can be done with perl functions downloaded with the dataset. it is the first time for me to work with .pl functions. i downloaded the program form this website https://platform.activestate.com/create-project?language=perl, and followed the setup steps.
now i have two problems: the first one, when i tried to run the function this error appeared "Can't open perl script "all_gen_cmf_image": No such file or directory", i have added the scripts directory using cd.
the second problem i don't know what he mean with this line "update the "vole" variable in the configuration file db_configs.pl, it should point to your vole binary of CMFD framework." in reedme file.
can any one helping me solving this problem?
Perl doesn't automatically try the .pl extension when you pass it the name of a script on the command line.[1] So, it fails because there isn't a script named "all_gen_cmf_image"; it's actually named "all_gen_cmf_image.pl". To run all_gen_cmf_image.pl you have to include the .pl part of the extension. Assuming you are in the scripts folder, the following should work:
perl all_gen_cmf_image.pl
or in the parent directory:
perl scripts/all_gen_cmf_image.pl
However, when Perl runs a use Module; statement, perl automatically adds .pm on the end and replaces any :: in the module name with a slash.

How to call nested script in sqlplus

I have following script hierarchy.
Scripts/master.sql
Scripts/GB/gb.sql
Scripts/GB/user1/insert.sql
master.sql contains simple #script to call gb.sql
e.g.
#GB/gb.sql
gb.sql contains below
#user1/insert.sql
The problem is that if i run master.sql from Scripts directory, i get below error:
unable to find insert.sql
Whereas if I execute gb.sql from GB directory, ir run successfully.
Can you please help me?
SQL*Plus directories are always reletive to the original working directory. Your scripts will need to repeat the full path from the working directory each time.
Change gb.sql to:
#GB/user1/insert.sql
The ## can be used to reference files in the same directory as the running file, but ## does not work with sub directories.

Running an executable by calling it in a .sh file

I am very new to bash and using .sh files. I am trying to run the program aescrypt by calling it in a .sh file as follows (aescrypt is in the same directory as the .sh file) :
./aescrypt -e -p password file.txt
It throws the following error:
./aescrypt no such file or directory
Am I doing it wrong?
ps- I realy don't want to add it to the PATH variable as I will be using this on more than one computer that resets every day.
The location of the script is irrelevant. The thing that matters is the working directory of the process executing the script. The simplest solution really is to add aescrypt to a standard location like /bin or /usr/bin. If neither of those is acceptable, perhaps /usr/local/bin is an option. Otherwise, just use the full path of aescrypt in your script. Either hard code it, or if it is in the same directory as the script, try:
$(dirname $0)/aescrypt ...
(Note that hardcoding is more reliable, but less flexible. If you move the executable, the script will break. But using dirname will break if the script changes directory during execution.)
how about if you call the program like ./aescrypt.sh, thats the way to call an .sh programm througt the terminal
First off all, you have also to change the permissions of the file to make it executable, the way to make that is to write in the terminal, the command:
sudo chmod 765 aescrypt.sh
For that you have to be located where the file is

How to run executable file in Apple Script

I'm trying to run a executable file using applescript in FileMaker.
I've been trying...
do shell script "./firstscript"
This results in the error "sh: ./firstscript: No such file or directory"
If I type './firstscript' directly in bash the file is properly being executed.
Any ideas on how I should be pointing to my executable file inside the apple script?
You probably have the wrong working directory - use a full path instead, e.g.
do shell script "/path/to/firstscript"

SQL script not executing in bash

I am running an SQL script from bash. One of the scripts seems to be running fine, but the other script fails. Can you please advise what might be the cause for the same?
#!/bin/bash
sqlplus -S user/password#database << EOF
whenever sqlerror exit sql.sqlcode;
set echo off
set heading off
#MyScript1
#MyScript2
exit;
EOF
Error:
SP2-0310: unable to open file "MyScript2.sql"
In Unix the access level for both is:
-rwxrwxrwx MyScript1.sql
-rwxrwxrwx MyScript2.sql
The error does give an indication that it is not able to access the file MyScript2.sql. But what I am curious about is how come it can access MyScript1.sql which is present in the same folder, but not MyScript2.sql?
Also if I run the file just in unix (using SQL*Plus) from the folder where the files are present it works fine. But if I run the same from a different folder it doesn't. Below example will explain it better
/Folder/having/the/files
both MyScript1.sql and MyScript2.sql run fine
/Some/random/folder
MyScript1.sql runs fine , but MyScript2.sql errors out
You said:
if I run the file just in unix (using SQL*Plus) from the folder where the
files are present it works fine. But if I run the same from a
different folder it doesn't.
If you run the bash script from a different folder to where you have the SQL files, how do you expect SQL*Plus to know where to find those? The question becomes not 'why can't it see MyScript2.sql, but why it can see MyScript1.sql. The obvious answer is that it can't, or at least can't see the version of the file you think it's seeing.
From the SQL*Plus documentation:
SQL*Plus searches for SQL scripts, including login.sql, in the current
directory and then in the directories specified by SQLPATH, and in the
subdirectories of SQLPATH directories.
So if you haven't given the full path to the SQL file, it will search in the current working directory - where you are sitting when you execute the bash script, not the directory the bash script is in, i.e. what pwd shows - and the in $SQLPATH if it is set.
That suggests you have a copy of MyScript1.sql in one of those places, or possibly a soft link to your real file. If I had to guess, I'd speculate that you originally wrote MyScript.sql the same directory as the script, then copied it to another directory before writing MyScript2.sql. In any case, the MyScript1.sql you're running might be out of date, or is likely to become so in the future.
The short answer is to give the full path to the SQL files, either as part of the # command, or by changing to that directory in the bash script before launching SQL*Plus.

Resources