Can I retrieve the output of a program, that is running in another terminal and/or run by root as e.g a cronjob? - ssh

Just for the sake of the question, say I open a terminal an log into my Linux computer. I run a program that keeps outputting information on my screen, looping. I close the terminal window, and the program shuts down.
I set up a cronjob or a startup script that launches the same program as in example 1. The program is looping now, run as root.
I open a terminal, and log into my computer through SSH. Can I make a Bash script that retrieves the output of said program, even if it's running somewhere in the background? I mean, is the program "virtually" outputting information (as in example 1)?

The program closes stdout and stderr when it exits. Looping it as you describe will just cause it to start and exit continuously. You could look at redirecting stdout and stderr.

Related

Send PDF to printer for printing using SSIS

I am trying to accomplish the task: printing PDF files at printer via SSIS silently.
I have tried different ways,
Execute Process Task + PDFtoPrinter: It works on my local machine, printouts available. On server, the job runs successfully, but no printout.
Execute Process Task + Adobe reader: It works on my local machine, but it opens GUI
Script Task + PDFtoPrinter: It works on my local machine, printouts available. On server, similar to solution 1, the job runs successfully, but no printout.
In general, I prefer using PDFtoPrinter.exe, but there is very limited log. I suspected, could it be it needs some wait time, so I put in some waits(30000), still did not solve the problem. Could it be possibly permission related? Having said that I am sure the exe and file folder are reachable.
I also tried to turn on SSIS log and it did not return any valuable insights. Any help is appreciated.
#Fields: event,computer,operator,source,sourceid,executionid,starttime,endtime,datacode,databytes,message
User:ExecuteProcessVariableRouting,xxx,xxx,Print pdf,{xxx},{xxx},06.12.2021 14:06:18,06.12.2021 14:06:18,0,,Routing stdout from variable "User::OutputFromPrinting"
User:ExecuteProcessVariableRouting,xxx,xxx,Print pdf,{xxx},{xxx},06.12.2021 14:06:18,06.12.2021 14:06:18,0,,Routing stderr from variable "User::ErrorFromPrinting"
User:ExecuteProcessExecutingProcess,xxx,xxx,Print pdf,{xxx},{xxx},06.12.2021 14:06:18,06.12.2021 14:06:18,0,,Executing the process "\xxx\PDFtoPrinter.exe" with the arguments ""\xxx\sample.pdf" "Printer1" /s ".
User:ExecuteProcessExecutingProcess,xxx,xxx,Print pdf,{xxx},{xxx},06.12.2021 14:06:34,06.12.2021 14:06:34,0,,Process has exited

Sending the Valgrind to the background

I'v started a process with valgrind to find the leaks with the option --leak-check=full and redirecting the stdout and stderr outputs to a file. But the program seems to be running too long and now I want to send the process to the background so that I can close the terminal and check on the results at later time.
Here I've found that by using ctrl +z it will suspend the process and with bg and disown commands its possible to remove the process from the terminal and run on the background
But when I try that with valgrind the process doesnot respond to the ctrl + z command
Is there an alternative way to send the valgrind process to background? Or am I doing the whole thing wrong?

Start program via ssh in Jenkins and using it in Jenkins build

Hello people.
I'm using Jenkins as CI server and I need to run some performance test using Jmeter. I've setup the plugin and configured my workspace and everything works ok, but I have to do some steps manually and I want a bit more of "automation".
Currently i have some small programs in a remote server. These programs make some specific validations, for instance (just to explain): validates e-mail addresses, phone numbers, etc.
So, before I run the build in jenkins, I have to manually start the program (file.sh) I want:
I have to use putty (or any othe ssh client) to conect to the server and then run, for instance, the command
./email_validation.sh
And the Jmeter test runs in a correct way, and when the test is done I have to manually "shut down" the program I started. But what I want is trying to start the program I need in Jenkins configuration (not manually outside Jenkins, but in "execute shell" or "execute remote shell using ssh" build step).
I have tried to start it, but it get stuck, because when Jenkins build finds the command
./email_validation.sh
the build stops, it waits for the command to finish and then it will continue the other build steps, but obviously, I need this step not to finish until the test is executed.
Is there a way to achieve this? Thanks
Run your command as a background process by adding the & symbol at the end of the command and use the nohup command in case the parent process gets a hangup signal, e.g.
nohup /path/to/email_validation.sh &
If the script produces any output, it will go by default to the file nohup.out in the current directory when the script was launched.
You can kill the process at the end of the build by running:
pkill email_validation.sh

How to run a PHP script via SSH and keep it running after I quit

I'm trying to restart a custom IRC bot. I tried various commands :
load.php
daemon load.php
daemon load.php &&
But that makes the script execute inside the console (I see all the output) and when I quit the bot quits as well.
The bot author only taught me the IRC commands so I'm a bit lost.
You can install a package called screen. Then, run screen -dm php load.php and resume with screen -dR
This will allow you to run the script in the background, and still be able to use your current SSH terminal. You can also logout and the process will still be running.
Chances are good the shell is sending the HUP signal to all its running children when you log out to indicate that "the line has been hung up" (a plain old telephone system modem reference to a line being "hung up" when disconnected. You know, because you "hang" the handset on the hook...)
The HUP signal will ask all programs to die conveniently.
Try this:
nohup load.php &
The nohup asks for the next program executed to ignore the HUP signal. See signal(7) and the nohup(1) manpages for details. The & asks the shell to execute the program in the background.
Clay's answer of using screen(1) is pretty awesome, definitely look into screen(1) or tmux(1), but I don't think that they are necessary for this problem.
This line might help you
php load.php &

valgrind on server process

hi i am new to valgrind. I know how to run valgrind on executable files from command line. But how do you run valgrind on server processes like apache/myqld/traffic server etc ..
I want to run valgrind on traffic server (http://incubator.apache.org/projects/trafficserver.html) to detect some memory leaks taking place in the plugin I have written.
Any suggestions ?
thanks,
pigol
You have to start the server under Valgrind's control. Simply take the server's normal start command, and prepend it with valgrind.
Valgrind will attach to every process your main "server" process spawns. When each thread or process ends, Valgrind will output its analysis, so I'd recommend piping that to a file (not sure if it comes out on stderr or stdout.)
If your usual start command is /usr/local/mysql/bin/mysqld, start the server instead with valgrind /usr/local/mysql/bin/mysqld.
If you usually start the service with a script (like /etc/init.d/mysql start) you'll probably need to look inside the script for the actual command the script executes, and run that instead of the script.
Don't forget to pass the --leak-check=full option to valgrind to get the memory leak report.