I found myself doing this all the time:
open terminal
cd /mydir/folder
parse deploy
Is it possible to create some kind of file I can click on, that does this automatically?
Thanks
create file run.sh and run - chmod +x run.sh
The file should look like this -
#!/bin/bash
cd /mydir/folder
parse deploy
Related
I have currently put together a script to move files from one directory to another.
This has gone ok however I was wondering if there was a way via a shell script to get it to run from anywhere on the server e.g I give the script for someone to use on their server and they can put the script anywhere and it will run.
I know a workaround is to put the script in /usr/local/bin or usr/bin and you can run it from anywhere but that is not what I want.
Is there a way that my script will auto run from usr/local/bin regardless of if it is in /scripts for instance?
Please see my script below:
#!/bin/sh -x
mkdir -p /var/Alitest
echo "This is a test that I have created. This is to
see if the output is successful I normally do this manually but a script is required" > /var/Alitest/action.txt
sed -i 's/This is a test that I have created/The test has been successful/g' /var/Alitest/action.txt
chmod 744 /var/Alitest/action.txt
chown root:root Alitest/action.txt
mv /var/Alitest/action.txt /script/action.txt
Any help would be greatly appreciated :)
Also in my log output for the script the following error is shown:
sed: 1: "/var/Alitest/action.txt": invalid command code A
Any ideas?
You can make a soft link in /usr/local/bin for your script. Then it will be in everyone's path to be executed.
e.g. ln -s /script/yourscript.sh /usr/local/bin/yourscript.sh
After reviewing the matter further I have decided the the best way to action this is to add the folder destination e.g /scripts to my path.
This can be done by vimming into the .bashrc file on the server and adding the below line:
export PATH=/dir_name:$PATH
remember to refresh the profile in order for the changes to take effect.
You can check if this has been successful by running the below command:
echo $PATH
There is no way to get your script to do this however this would be better then a softlink as if you add it to $PATH then you do not have to go through the task of adding softlinks each time.
Thank you all for your help.
Kind Regards
Ali
I dont know how to write 2 commands (which I enter in terminal) as a script.
I wrote file "my.sh" with 2 lines, then double-clicked it.
I need ~/mydir path with tilde.
cd ~/mydir
make
File opens in Xcode editor.
How to write it OK and run by dbl-click?
You need to save it as a .command:
my.command
#!/bin/bash
cd ~/mydir
make
If it doesn't do anything upon double-clicking you might need to chmod it:
chmod +x my.command
I create a python executable in Raspbian with cxfreeze and then I want execute a executable in terminal, but it doesn't work. Any ideas?
Thanks
Python script code:
!/usr/bin/env python
print "hello"
Image Raspbian
add an execution permission to the file.
Open termnial and cd to the folder where the file is.
After that is done:
chmod u+x file_name
When I create .sh file, I need to give permission for him to be executed, there is a file that can be configured or command applied so I can already create the file with permission of execution?
Through Terminal, type in this command:
chmod +x file.sh
To execute the command, do:
./file.sh
If you want an application, you can make an Automator using the previous commands.
I'm trying to learn to write shell scripts and use the Terminal.
In Users/user/Development/linux I've got a script called sysinfo_page.
So I'm in the linux folder in the terminal and I can see the sysinfo_page when I type the ls command.
However, when I enter the following command:
sysinfo_page > sysinfo_page.html
I receive the following message:
-bash: sysinfo_page: command not found
How do I resolve this?
If you want to run a script file form the current directory, you have to write ./ before your script name:
./script.sh
Your command may not be an executable file. Try this:
chmod +x sysinfo_page
./sysinfo_page > sysinfo_page.html
The first line will set the eXecutable flag on the file, the second will run it from the current dir. Note that if you want to run a file in the current directory and that dir is not included in your PATH, you need to prepend ./ or else the shell won't find it.