How can I run a Java .jar file, fx “java -jar MyJar.jar” automatically on a Linux server, instead every time I login and run it from ssh? I am looking for some way to automatically execute that command, or something to that effect. Also, how can I direct all output to some logfile? (I guess stdio …
Tag: shell
Shell script: Run function from script over ssh
Is there any clever way to run a local Bash function on a remote host over ssh? For example: Yeah, I know it doesn’t work, but is there a way to achieve this? Answer You can use the typeset command to make your functions available on a remote machine via ssh. There are several options depending on how y…
Get lines that end with “$” in a text file
I have an output like this: What i want is just this line: To be more clear, I want those line ending with a specific string. I want to grep lines that have a / character at their last column. Answer You can use $ like this: As $ stands for end of line, /$ matches those lines whose last
How to execute a command on behalf of a user if login is denied
I need to run tomcat on behalf of tomcat user. But in /etc/passwd I have the following line: So when I try to do this: sudo su tomcat ./bin/startup.sh It complains about: su: /bin/nologin: No such file or directory How do I execute the command with proper permissions? Thanks in advance! P.S. I’m trying …
Run processes with priority from shell (not “nice” )
I am looking for the equivalent command to nice, but for setting process priority and selecting the scheduler to use. I need to be able to type (or include in a script) something like run-with-scheduler batch a-big-long-command, or run-with-scheduler round-robin priority 10 to set the process priority and sch…
How to run VLC stream on Linux server using Java code?
I am trying to run vlc stream from my Java code on Debian server. Simple commands as given in the example below works fine both from java code as well as terminal. But I try to run more advanced command with multiple options” This is my main class: and this is class for executing shell commands: Process…
How to find the latest folder in a directory and then make a full path accordingly?
I have a directory which will have some folders and some files within it. Suppose this is my current directory as shown below with pwd command – And I am logged into machineA. This /bat/data/snapshot directory will have some folders and some files within it as shown below – So the two folders I ha…
Find the sum of an infinite series
How can I find the sum of an infinite series? Series: My misbehaving example: Is it possible to carry out this method correct calculation or how to resolve this problem in other ways? Answer This series does not converge. It’s called the harmonic series and it’s known to do not converge. Moreover,…
Why does bash behave differently, when it is called as sh?
I have an ubuntu machine with default shell set to bash and both ways to the binary in $PATH: But when I try to call a script that uses the inline file descriptor (that only bash can handle, but not sh) both calls behave differently: The example-script I am referring to looks like that the real one is a littl…
How to move all files including hidden files into parent directory via *
Its must be a popular question but I could not find an answer. How to move all files via * including hidden files as well to parent directory like this: This will move all files to parent directory like expected but will not move hidden files. How to do that? Answer You can find a comprehensive set of solutio…