Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to Linux commands. I have a requirement where I want to start Tomcat using a shell script. The location of startup.sh file is in /usr/lib/apache-tomcat-7.0.14/bin/. Tomcat is starting using command sh startup.sh. I want to create a shell script so that it will go to that folder and will execute sh startup.sh command. How can I do this using a shell script? Can anyone share the script for doing this?
Are you serious?
#!/bin/bash
cd /usr/lib/apache-tomcat-7.0.14/bin/
sh startup.sh
#!/bin/bash
exec /usr/lib/apache-tomcat-7.0.14/bin/startup.sh
is simpler (as does not have a shell kicking around)
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
My understanding is that all commands in linux must exist on the $PATH, even for the most basic commands
> which cd
/bin/cd
> which ls
/bin/ls
But when I tried which pushd, to my surprise, it returned:
/usr/bin/which: no pushd in (/bin:/usr/share/maven/bin:/usr/share/java/jdk1.8.0_131/bin:/usr/local/bin:/usr/bin:/usr/local/sbin)
pushd is "installed" and working. This challenges my whole understanding of linux commands.
Can someone explain why this is happening?
Can someone explain why this is happening?
pushd, like many other commands, is a builtin. which is itself an executable and which searches for executables - there is no such executable as pushd.
To affect the current working directory of the shell itself, it has to be a builtin, just like cd.
You can check what it is with type:
$ type pushd
pushd is a shell builtin
what are other examples of such shell builtins?
They are listed in documentation: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Builtin-Commands .
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am using the command:
#!/bin/ksh
as the first line in my shell script (hopefully this will dictate the shell to execute in the KSH Shell) . But when i am executing my shell like below it is not actually happening.
sh test_shell.txt
But when i using like below with or with out (#!/bin/ksh) i am getting proper output.
ksh test_shell.txt
In my code i am setting a value to variable like below.
set -A variable_name
But i think -A is not recognized in sh where as it is working as an assignment in ksh shell.
How can I resolve this?
When you execute
sh test_shell.txt
then you are launching the sh (Bourne) shell with your file name as the script to run. In this case the first line of the script is ignored because it is a comment. The rest of the script is expected to be in Bourne shell syntax, because that's the shell you requested.
If you set your script to executable (chmod +x test_shell.txt) and then run it with:
./test_shell.txt
then the kernel will read the first line of the script, see it starts with the special #!, and run your script with /bin/ksh.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to write a script to run one of my .jar files as daemons, but I am not understanding how to create a .sh extension file in Ubuntu. I have already used vi to create a file with the code that I want, but I cannot figure out how to define the file to specifically be a .sh file. For example, I want to convert my file "foo" or "foo.txt" into "foo.sh".
Is there a simple command I am not seeing that can convert files to a .sh extension or is it a more complicated process?
Use this as a template:
#!/bin/bash
# content of your script
The first line is called a shebang and tells the OS what program that should be used executing the content of the file, in this case, bash.
To make the file executable:
chmod 755 foo.sh
To execute your script do:
./foo.sh
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am working on a Linux server, I have access to a directory but I am not allowed to write anything to that directory. I can run commands from system prompt. Now I have to find values of specific field of some files in that dir and do some comparisons. I have a script on a test server can do that. But I can't install my script to the server, I am asking if there is anyway I type a specific command, then I can write and run a shell program without saving the program? Thank you!
If you have the script on another host, you can run it this way:
wget http://your.host.net/script -O- | sh -s
If the host is not accessible via HTTP, you can use any other protocol you want.
Also you can write a script direct in a shell:
sh -s <<EOF
echo Hello
echo I am script
echo Nice to meet you
EOF
You can use backtics to execute the result of another command.
`wget /path/to/your/script/stored/remotely -O-`
(you might use sftp to fetch the script instead)
Another option is to write a program that uses a tty to control an ssh session, then the script is stored on the ssh client but the commands run on the server. Perhaps the expect tool would help with that.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
How do I execute a script on ssh? I need to execute:
/scripts/makecpphp
So I have tried run /scripts/makecpphp but it didn't work. Any help would be greatly appreciate. I know for sure that that file exists there.
If the script is on the remote machine:
ssh user#foo.example.com /scripts/makecpphp
If it's on the local machine:
/scripts/makecpphp
If makecpphp is executable, you just need to type:
./scripts/makecpphp
Are you sure it's executable? Note that this does not just apply over ssh, but any time you are running programs via a linux command line.
If it's executable, just do
/scripts/makecpphp
Otherwise you can do (replace $INTERPRETER by the used interpreter, eg bash, python,...)
$INTERPRETER /scripts/makecpphp
First off, do you have the permission to execute it and is it executable?
Secondly, I don't believe you would use run. You'd cd to the directory and then type
./makecpphp
you need to have execute permission on the script.
chmod +x /scripts/makecpphp
then run
/scripts/makecpphp