date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,389,826,534,000 |
Is it possible to customise the bash prompt to show the if there are any background jobs? I find it easy to forget that there are background jobs.
Say if the prompt was...
$
Is there a way to make it show the number of background jobs? For example, if there were two background jobs sent to the background using CTRL... |
Put \j in your prompt. From the bash manual:
\j
The number of jobs currently managed by the shell
Just remember that prompts do go stale and jobs can finish at any time, so if you have left the terminal idle, you'll want to redisplay the prompt.
At the cost of requiring an extra process just to print your pr... | Is it possible to customise the prompt to show the if there are any background jobs? |
1,389,826,534,000 |
I would like to know how to stop a running process after appending it with &.
For example, I would like to install software foo. Now, assume, foo has many dependancies, it takes an hour to finish. So, I do: yum install foo &. But I would like to stop that on-going process either by making it foreground (the actual pr... |
If the terminal you launched the command from is still open, you can get it back by running fg.
If it is not, identify the process ID by running ps aux | grep yum or just pgrep yum and then use kill PID. Or, if you know you only have one yum instance, run pkill yum.
| How to return a background task to be in the foreground? |
1,389,826,534,000 |
I can grep the output of jobs, and I can grep the output of a function. But why can't I grep the output of jobs when it's in a function?
$ # yes, i can grep jobs
$ jobs
[1]+ Running vim
[2]+ Stopped matlab
$ jobs | grep vim
[1]+ Running vim
$ # yes, of course i can grep a function
$ typ... |
Eric Blake answered on the bash-bugs mailing list:
jobs is an interesting builtin - the set of jobs in a parent shell is
DIFFERENT than the set of jobs in a subshell. Bash normally creates a
subshell in order to do a pipeline, and since there are no jobs in that
subshell, the hidden execution of jobs has nothi... | Cannot grep jobs list when jobs called in a function |
1,389,826,534,000 |
When i look at the jobs -x explanations, it says:
If the -x option is supplied, jobs replaces any jobspec found in command or arguments with the corresponding process group ID, and executes command, passing it arguments, returning its exit status.
Without an example, this explanation is extremely inadequate. If poss... |
Example:
$ sleep 300 &
[1] 16012
$ echo %1
%1
$ jobs -x echo %1
16012
Here %1 is the jobspec. The number was taken from [1] shown just after the job was created. Without jobs -x %1 is just a string, so echo %1 prints the string. jobs -x replaces the jobspec with the corresponding process group ID before running echo.... | Usage example of "x" option of "jobs" command in bash |
1,389,826,534,000 |
If I disown a job in bash and change my mind, can I undo it somehow ?
If so, taking it further, is it possible to bring an arbitrary process under job control (an acceptable restriction would be that I own the process) ?
And, finally, would this make the below workflow possible:
put job in background (^z followed by... |
In general, it isn't possible for a shell to “adopt” a job. For a shell, a job means a few things:
Associate a job identifier with a process ID.
Display its status (running, suspended, dead).
Notify the user when the status changes.
Send a SIGHUP signal when the terminal goes away.
Control whether the job “owns” the ... | Is it possible to add a process to the job list in bash (e.g. to reverse "disown")? |
1,389,826,534,000 |
I have a job that runs in the background via ctrl + z and bg, and after reconnecting ssh I cannot find that job in the jobs command but can find it in ps grep. For now, I searched this and I get the tmux may be a better solution, however, I am still wondering why exit ssh will lose jobs in the jobs command. I've put t... |
Shell jobs don't belong directly to the user. I mean there is no global list of jobs for the user. A job can be a process that belongs to the user and you can find all processes belonging to the user. But each job as a job belongs to some shell process, the shell keeps a list and tracks its jobs. If the shell process ... | Why jobs lost when after reconnect ssh? |
1,389,826,534,000 |
From gnome-terminal I know the ability to suspend a job with C-z, and then send it to the background. When I close the terminal the process does not end. Where is the job being managed from, or is it lost?
|
Your background job continues executing until someone tells it to stop by sending it a signal. There are several ways it might die:
When the terminal goes away for any reason, it sends a HUP signal (“hangup”, as in modem hangup) to the shell running inside it (more precisely, to the controlling process) and to the pr... | Where do background jobs go? |
1,389,826,534,000 |
If I have a Bash script like:
function repeat {
while :; do
echo repeating; sleep 1
done
}
repeat &
echo running once
running once is printed once but repeat's fork lives forever, printing endlessly.
How should I prevent repeat from continuing to run after the script which created it has exited?
I th... |
This kills the background process before the script exits:
trap '[ "$pid" ] && kill "$pid"' EXIT
function repeat {
while :; do
echo repeating; sleep 1
done
}
repeat &
pid=$!
echo running once
How it works
trap '[ "$pid" ] && kill "$pid"' EXIT
This creates a trap. Whenever the script is about to exi... | Prevent a shell fork from living longer than its initiator? |
1,389,826,534,000 |
I understand that when I run exit it terminates my current shell because exit command run in the same shell. I also understand that when I run exit & then original shell will not terminate because & ensures that the command is run in sub-shell resulting that exit will terminate this sub-shell and return back to origin... |
Until I started answering this question, I hadn’t realised that using the & control operator to run a job in the background starts a subshell. Subshells are created when commands are wrapped in parentheses or form part of a pipeline (each command in a pipeline is executed in its own subshell).
The Lists of Commands s... | Why is subshell created by background control operator (&) not displayed under pstree |
1,389,826,534,000 |
I want to know why after disowning the stopped process, it is still appearing the process table
PING www.google.com (74.125.130.106) 56(84) bytes of data.
64 bytes from 74.125.130.106: icmp_seq=1 ttl=44 time=182 ms
64 bytes from 74.125.130.106: icmp_seq=2 ttl=44 time=209 ms
64 bytes from 74.125.130.106: icmp_seq=3 ttl... |
No, the process is stopped, not killed. So ps will still show it.
If you run ps ax, you will see its status is T. In this state, the process will do nothing until it receives a SIGCONT, then it will continue to run (if you type fg in your terminal, you'll see the process starting again from the point it stopped, so in... | Disowned "Stopped" job process still appears in process table |
1,389,826,534,000 |
I am trying to create a fun Terminal Screensaver which consists of the cmatrix package (one that turns terminal in one similar to the movie The Matrix) and xprintidle to determine idle time of the Terminal.
I took some help from this Thread answer at SuperUser and using a shell-script similar to it as follows:
screens... |
The fg job commands are connected to interactive sessions only, and have no meaning in batch mode (scripts).
Technically, you could enable them with set -m, but it still would make little (if any) sense, as this only relates to interactive applications where you can send jobs to back by ^Z, but since you don't have th... | Is it possible to use commands like `fg` in a shell-script? |
1,389,826,534,000 |
I am trying to check how many active processes are running in a bash script. The idea is to keep x processes running and when one finished then the next process is started.
For testing purposes I set up this script:
find $HOME/Downloads -name "dummy" &
find $HOME/Downloads -name "dummy" &
find $HOME/Downloads -name "d... |
The problem with the script is that there is nothing in it which is going to call one of the wait system calls. Generally until something calls wait the kernel is going to keep an entry for the process as this is where the return code of the child process is stored. If a parent process ends before a child process the ... | Waiting for any process to finish in bash script |
1,389,826,534,000 |
Normally, when a job is launched in the background, jobs will report that it is finished the first time it is run after the job's completion, and nothing for subsequent executions:
$ ping -c 4 localhost &>/dev/null &
[1] 9666
$ jobs
[1]+ Running ping -c 4 localhost &> /dev/null &
$ jobs
[1]+ Done ... |
You know, of course, that $(…) causes the command(s) within the parentheses
to run in a subshell. And you know, of course, that jobs is a shell builtin.
Well, it looks like jobs clears a job from the shell’s memory
once its death has been reported.
But, when you run $(jobs), the jobs command runs in a subshell,
so ... | Why does 'jobs' always return a line for finished processes when run in a subshell within a script? |
1,389,826,534,000 |
When does the jobs command issue the message jobs : not found?
Also, why does the command man jobs refuse to show any entry for the command jobs?
P.S. : I am able to successfully execute the jobs command on the terminal
|
jobs is not a real command, but a command that is builtin to the shell that you're using:
martin@dogmeat:~$ type jobs
jobs is a shell builtin
When you try to run it without a shell, you'll get an error message, because there is no binary executable called jobs.
It also doesn't have a manpage because it's just a built... | When does one get the error message "jobs : not found"? |
1,389,826,534,000 |
Minimal effort to reproduce what I am looking for, is as follows
/$ sleep 1h &
[1] 6564
/$ cd
~$ jobs
[1]+ Running sleep 1h & (wd: /)
When I use jobs to manage my background processes, the working directory (wd) is also displayed when it is different from the current directory.
Is there an easy way ... |
If your intent is to get the working directory of a process, this is one way:
~ » jobs -l
[1] + 14308 running sleep 1h
~ » readlink /proc/14308/cwd
/home/matti-nillu
The following function inside .bashrc, will do exactly what you want
cdjob ()
{
pid=$(jobs -p $1);
d=$(readlink /proc/$pid/cwd);
cd "$... | Quick access to work directory of background job |
1,389,826,534,000 |
I was trying to install OpenCV in Ubuntu based on few guides online. One of the guides is this one. It has the following line:
make -j $(($(nproc) + 1))
The nproc returns the number of processors/ threads available on the system. So, what is the advantage of going one higher than what's available?
|
Most builds are I/O-limited, not CPU-limited, so while nproc is a decent starting point (see also How to determine the maximum number to pass to make -j option?), most builds can use more than that. This is especially true if you’re using small VMs to build, which you’ll often find on build farms; there you’d end up w... | What is the logic of using $($(nproc) + 1) in make command? |
1,389,826,534,000 |
If I run jobs -l on command prompt it shows me the status of running jobs but if I run below file ./tmp.sh
#! /bin/bash
jobs -l
It shows empty output.
Why is that and how can I obtain information about a status of a particular job inside of a shell script?
|
jobs
shows the jobs managed by the current shell. Your script runs inside its own shell, so jobs there will only show jobs managed by the script's shell...
To see this in action, run
#!/bin/bash
sleep 60 &
jobs -l
To see information about "jobs" started before a shell script, inside the script, you need to treat them... | Why does the jobs command not work in shell script? |
1,389,826,534,000 |
Is there a way to make jobs -p in zsh behave as in bash, ie. give
only a number, such that one can do kill $(jobs -p)?
|
jobs reports about jobs, which can have more than one process.
When interactive, jobs are placed in process groups, so they can be suspended/resumed/interrupted as a whole.
jobs -p (in both zsh and bash) returns the process group id of each job, not the process ids of all the processes in the job.
When the shell doesn... | Making zsh jobs -p behave as in bash |
1,389,826,534,000 |
I would like picocom to log serial data on a remote computer, without having to keep my ssh session to the remote computer alive.
I have tried:
picocom <my options>
This dies when I logout.
picocom <my options> &
No output on terminal, and exiting picocom with C-a C-x leaves the job as stopped, it doesn't kill it... |
An alternative is to setup the device with stty, then read it with cat:
stty <my options>
nohup sh -c "cat /dev/ttyACM0 > data.log" &
| Running picocom in the background without open session |
1,389,826,534,000 |
I have a script that runs some programs in the background, but after running it, they are not listed by the command 'jobs'. Why is this?
(./m_prog -t m_prog1 m_config) &
(./m_prog -t m_prog2 m_config) &
(./m_prog -t m_prog3 m_config) &
But if I execute each one of them from the terminal, they do appear in 'jobs'
... |
jobs works only for the instantiation of the shell that created the jobs. jobs n use numbers not the pid. Once the shell is run inside a script (another new process), the old shell that launched the script, jobs (issued in the old shell) no longer can reference job # 1 in the new shell.
Why? Because the current shel... | why jobs doesn't list commands from script |
1,389,826,534,000 |
$ command1 && command2 && command3
Running command1 ...
Running command2 ...^Z
[1]+ Stopped
$ fg && command4 && wrong_command5 && command6
Running command3
Running command4
How do I cancel the wrong_command5, scheduling right_command5 instead after the termination of currently running command4?
|
If command4 is currently running, it is possible to do this pretty straightforwardly:
^Z
$ fg && right_command5 && command6
This is essentially what you were already doing to start command4 in the first place. wrong_command5 and the rest will be replaced and never execute.
I think that behaviour is going to be unexpe... | How do I cancel/replace one element of running `cmd1 && cmd2 && cmd3 && ...` chain? |
1,389,826,534,000 |
I'd like to add an indicator to my PS1, showing whether there is a process suspended with ctrl+z. In order to do so, I'll need a function that is able to check for this situation. I'm not even sure where to start to think about this problem. Google has failed me. Any ideas?
|
“Process suspended with Ctrl+Z” is actually a subset of “suspended process that's a child of this shell”, and it's easier to track: that means there's a suspended background job.
In zsh, you can check the jobstates array.
if ((${(M)#jobstates:#suspended:*} == 0)); then
echo There are no suspended jobs
else
echo Th... | Shell function to check if there is a suspended process that's a child of this shell? |
1,389,826,534,000 |
I need to retrieve the PID of a process piped into another process that together are spawned as a background job in bash. Previously I simply relied on pgrep, but as it turns out there can be a delay of >2s before pgrep is able to find the process:
#!/bin/bash
cmd1 | cmd2 &
pid=$(pgrep cmd1) # emtpy in about 1/10
I f... |
When a background job is a pipeline of the form cmd1 | cmd2, it's still a single background job. There's no way to know when cmd1 starts.
Each & creates one background job. As soon as cmd & returns, the shell is aware of that background job: cmd & jobs lists cmd. cmd & pid=$! sets pid to the process ID that runs cmd.
... | Reliable way to get PID of piped background process |
1,389,826,534,000 |
I like my background processes to freely write to the tty. stty -tostop is already the default in my zsh (I don't know why, perhaps because of OhMyzsh?):
❯ stty -a |rg tostop
isig icanon iexten echo echoe echok -echon... |
A process can be sent that SIGTTOU signal (which causes that message), when it makes a TCSETSW or TCSETS ioctl() for instance (like when using the tcsetattr() libc function) to set the tty line discipline settings while not in the foreground process group of a terminal (like when invoked in background from an interac... | zsh: Why do I get suspended background processes even when I have `stty -tostop`? |
1,525,494,603,000 |
If I ssh to a box and start a task that will take some time to complete I usually press control+z to pause the process, and then immediately type bg 1 to put run it in the background.
I can then type jobs and see it running.
If I disconnect (type exit, press control+d, etc) and then log back in, I can no longer type j... |
You can use kill -STOP pid to pause a job and kill -CONT pid to resume it. You get the proper pid from the ps command you already know.
| How can I manage jobs after I disconnect from my tty/ssh session? |
1,525,494,603,000 |
I have written following function in my bashrc. It checks if a job is running every 5 seconds and sends email when job is finished.
function jobcheck () {
time=`date`
jobstatus=`jobs $1`
while [ 1 ]; do
if (( ! `echo $jobstatus | grep "Running" | wc -l` )); then
"sendEmail command to send email"
break;... |
You will have to rewrite your function to be able to do that.
When you start a background job with &, the shell does indeed keep track of that, and you can indeed figure out more information by using the jobs builtin. However, that information is specific to that instance of the shell; if you run your function with & ... | bash function that sends email after job is finished |
1,525,494,603,000 |
While studying the internals of bash's job control mechanism under Linux I have came across a little problem of understanding. Let's assume the following scenario:
script is executed in background
user@linux:~# ./script.sh &
same script is executed in foreground at the same time
user@linux:~# ./script.sh
Now the first... |
Yes, bash uses waitpid() with WNOHANG in a loop. You can see this in waitchld() in jobs.c:
static int
waitchld (wpid, block)
pid_t wpid;
int block;
{
...
do
{
/* We don't want to be notified about jobs stopping if job control
is not active. XXX - was interactive_shell instead of job_c... | How does bash's job control handle stopped or terminated background jobs? |
1,525,494,603,000 |
When putting a job in background with the command bg, I have the output of the command of the job.
How to put the job in background (like the bg command) but without any output?
PS: the job is linked to a command with an output (there is no >/dev/null 2>1 in the original command)
|
You need to tell the now backgrounded application to stop writing on the tty device. There is no generic way to do that.
You can do:
stty tostop
to make so that background jobs be suspended (with a SIGTTOU signal) when they try to write to the tty.
You can attach a debugger to the process and make it re-open the file... | How to put a job in background without output? [duplicate] |
1,525,494,603,000 |
I have a script called go.sh
python3 bob.py &> lol.log &
python3 alice.py &> lol2.log &
When I run ./go.sh and then run jobs. Neither one of the jobs that I've executed in go.sh appear in jobs. In fact, nothing appears in jobs.
Yet, when I run each command in go.sh by one, it does appear in jobs.
How can I fix this?... |
I assume you run go.sh & not just go.sh and then jobs, as this is trivial (no job would be expected to be reported once it's over).
Your script starts two jobs in the background and it's done. So you don't see it. You don't see also the jobs started by the script as it's another shell. If you want to see the jobs, ins... | Jobs not appearing in `jobs` |
1,525,494,603,000 |
Trying here to modify a job from at command.
Any idea on how to do it?
Already managed to list it, delete, and execute, but can't modify it.
|
If you just need to fix a typo in the shell language itself, look for your job in directory /var/spool/cron/atjobs:
# type -p date | at 1430
warning: commands will be executed using /bin/sh
job 2 at Fri Aug 23 14:30:00 2019
# atq
2 Fri Aug 23 14:30:00 2019 a root
# ls /var/spool/cron/atjobs/
a00002018e67ea*
# ca... | Editing a job in At command |
1,525,494,603,000 |
Job control is probably my favorite thing about Linux. I find myself, often, starting a computationally demanding process that basically renders a computer unusable for up to days at a time, and being thankful that there is always CTRL-Z and fg, in case I need to use that particular computer during that particular tim... |
There is no job stack, each job is handled independently.
You can do fg; otherbigjob. That will put reallybigjob back to the foreground, then when the fg command stops run otherbigjob. This isn't the same thing as queuing otherbigjob for execution after the first job: if you press Ctrl+Z then otherbigjob starts immedi... | Basic job control: stop a job, add a job onto the stack, and `fg` |
1,525,494,603,000 |
I have a process that is blocking in nature. It is executed first. In order to execute the second process, I moved the first process to the background and executed the second process. Using the wait statement, I am waiting in the terminal. However, it seems that upon exiting the shell (pressing CTRL+C), the first proc... |
You could also trap for an interrupt to ensure the process is killed if ctrl+c is pressed
#!/bin/sh
trap ctrl_c INT
ctrl_c () {
kill "$bpid"
exit
}
# start process one in background
python3 -m http.server 8086 &
bpid=$!
# start second process
firefox "http://localhost:8086/index.html"
wait
| Call other process after executing a blocking process in shell |
1,525,494,603,000 |
Would someone explain if & why disown is necessary if you wish to keep a job running even after you disconnect.
I ask because every site I have visited says to use disown and bg but bg on its own is working for me and I'm not sure why.
Is it because I haven't fully understood what disown is for or are there some setti... |
Processes backgrounded via bg or & will typically die under 2 scenarios:
The shell receives a SIGHUP
They try to write to a terminal which no longer exists.
Item #1 is the primary culprit when closing your terminal. However whether it happens or not depends on how you close your terminal. You can close it by:
Somet... | Is it necessary to disown a process for it to continue running after disconnecting? |
1,525,494,603,000 |
If I have the following jobs running in a shell
-> % jobs -l
[1] 83664 suspended nvim
[2] 84330 suspended python
[3] 84344 suspended python
[4] 84376 suspended nvim
[5] - 84701 suspended python
[6] + 84715 suspended python
How can i return to the nth job, suppose I want to return to job 4, or job ... |
To return to job 4, run:
fg %4
The command fg tells the shell to move job %4 to the foreground. For more information, run help fg at the command prompt.
When you want to suspend the job you are working on, run bg. For more information, run help bg at the command prompt.
For more detail than you'd likely want to kno... | Return to a particular job in the jobs list |
1,525,494,603,000 |
The output of jobs looks something like this
[1] Stopped TERM=xterm-256color vim --servername vim ~/.gitconfig
[2]- Stopped TERM=xterm-256color vim --servername vim ~/.vimrc (wd: ~)
[3]+ Stopped TERM=xterm-256color vim --servername vim i3blocks.conf (wd: ~/.config/... |
In zsh, the $jobdirs associative array maps job numbers to the working directory they were started from, so you can do cd $jobdirs[n] to cd into job n's directory (or cd ${jobdirs[n]?} to get an error instead of taking you home if the job doesn't exist).
~$ jobs -d
[1] - running sleep 1000
(pwd : /tmp)
[2] + sus... | Is there a way to quickly change dir to one from where one of the jobs is running? |
1,525,494,603,000 |
I have an analysis program and a text file with data in it which for the sake of exposition I will call wibble and data.txt respectively.
I tried a simple for loop to process all of my data:for i in $(cat data.txt); do
wibble $i
done
But it takes a very long time to finish the analysis one by one.
So I tried ma... |
With GNU xargs:
xargs -rn 1 -P 5 -a file wibble
That runs up to 5 wibble commands in Parallel each taking 1 word from the file as argument.
For GNU xargs words are delimited by sequences of space, tab or newline character and with single quotes, double quotes and backslash recognised as quoting operators for those de... | How do I process my data file in bunches (without using the app parallel)? [duplicate] |
1,525,494,603,000 |
Here are two cases when a process group in an interactive shell isn't a job of the shell:
$ sleep 100 &
[1] 16081
$ jobs
[1]+ Running sleep 100 &
$ disown %1
$ jobs
$
and
$ ( sleep 200 & )
$ jobs
$
How does each case achieve making a process group not a job? In interactive bash, what is the necess... |
In both cases, the process group does start out as a job of the shell. When you call disown %1, the shell removes that entry from its list of jobs: that's the whole point of disown. With ( sleep 200 & ), the sleep process is a job of the subshell created by the parentheses; you can see that by running ( sleep 200 & jo... | In bash, a process group is a job if and only if ...? |
1,525,494,603,000 |
I am pretty new to unix systems and their workings. Is there any way to schedule a cron job in unix which runs on every day 12:00 AM and checks if the day is Thursday it stops a service and if the day is Friday it starts the service again?
|
You're overcomplicating it by trying to make one job that conditionally does two things. You want one job to start the service on Thursday, and another to start it on Friday, as in the following cron table.
0 0 * * 4 service myspiffyservice stop > /dev/null 2>&1 # stop myspiffyservice on Thursday
0 0 * * 5 service ... | scheduling cron jobs to stop a service on Thursday and start it on Friday |
1,525,494,603,000 |
Here is the scenario:
Let's say that I log into my server via ssh and start an emacs or vi (or whatever other program) session. Then my ssh connection disconnects.
Is there a way for me to reconnect to those programs via a new ssh session. In other words, when I log back into my server through a new ssh session?. In ... |
You can use screen
Suppose you have logged in using SSH, then simply run following command to create screen session called 'mysession'
screen -S mysession
in case your connection disconnected, then you can simply attach your session using:
screen -x mysession
Check this link for more information about screen
| How to resume a program when logged in with different session |
1,525,494,603,000 |
for i in $( seq 1 $1 )
do
kill %$i
done
I try to kill the stopped jobs with this script, but interestingly it can't be able to even though I have jobs open.
$ jobs
[10] Stopped vim detect_thread.py
[11] Stopped python3 detect.py
[12]- Stopped python3 detect... |
The kill builtin only recognizes the %N format for jobs running in the current shell. However, shell scripts run in their own separate subshell and in that subshell, there are no jobs to kill. This might be clearer with an example:
$ for i in {1..5}; do sleep 100 & done
[1] 2259152
[2] 2259153
[3] 2259154
[4] 2259155
... | Can't kill stopped jobs with bash script |
1,525,494,603,000 |
Suppose, as a dummy example, I execute a bash command in one terminal tab:
$: sleep 1000 &
Then, in another tab, I run the command that should "kill all background jobs":
$: jobs -p | xargs -a kill
Except nothing happens. Or, better yet: how does one list all jobs started by my user via <some-job> & from any contex... |
The jobs command is a shell builtin, so is only intended for the current shell instantiation. In particular, the Bash manual describes jobs as:
-p List only the process ID of the job's process group leader.
(Emphasis mine.)
If you run jobs -l, you'll see that the sleep which you backgrounded in the other shell i... | How does one kill jobs submitted via bg in one subshell from another shell instance? |
1,525,494,603,000 |
I can't make sense of these return values.
When I run jobs -s | wc -l, I get different results depending on what directory I'm in.
If I'm in the directory that I returned to after suspending the job, I get the correct answer.
If I'm in any other directory, I get the correct answer + 1.
See screenshot:
I also ran job... |
Because there are two lines in later case, one being shown, one not because it is being shown in a subshell with a trailing newline that is being counted. I have checked zsh and bash, this behavior exists in zsh, bash behaves similarly with different formatting.
Take a look at the following ASCII dump from zsh:
/tmp/t... | jobs / wc: getting weird return values |
1,525,494,603,000 |
After a recent workspace reorganization, I am left with a question about the way certain processes interact with the output of jobs.
I am running all of my program in the background on one 'Main' terminal, that way I have control and information from them all neatly in one place. what I have noticed is that when I cr... |
As you noted, invoking firefox a second time will simply ask the running instance to open another window. The -no-remote switch can be used to inhibit this behavior.
Something similar happens with nautilus: it is used to display the desktop window (with it's icons), so it's already running when you start it.
| Some processes not remaining in jobs list |
1,525,494,603,000 |
As you can see in the following output the variable $i in the output of ps aux is expanded to sleep 1, sleep 2, etc.
Is there a way to make zsh do the same? In the jobs output all the commands get the same name, which is sleep $i.
$ for i in {1..10}; do sleep $i& done; ps aux | grep sleep; jobs
[6] 1630
[7] 1631
[8] 1... |
Note that it's not processes you put in foreground, but jobs, made of a shell command which could be a compound command starting several processes in parallel (like in sleep 10 | sleep 20 &) or one after the other (like in for i in {1..10}; do sleep $i; done &).
And each of these process could in turn start more proce... | How to get variables expanded in output of jobs command |
1,525,494,603,000 |
I'm working with some tail -f path/to/my/log/file | grep pattern& and I need to kill the process as quick as possible.
With classic kill {tail PID}, tail still displays its buffer and it takes around 12 second (on my setup) to get tail completely silent.
However, it's much faster when I kill it with kill %{job id} (sl... |
When you kill the job with kill %6, you kill the tail and kill grep too.
tail -f /var/log/mintupdate.log|grep ez&
[6] 3368377
If you kill 3368377, you kill just the grep process.
3368376 pts/6 S 0:00 tail -f /var/log/mintupdate.log
3368377 pts/6 S 0:00 grep --color=auto ez
Of course it caused to kill... | "kill %{job id}" vs "kill {job pid}" |
1,525,494,603,000 |
I’ve got 2 background jobs running, I got their job ids using jobs is it possible to bring them both to the foreground using the fg <jobId> cmd? I can’t seem to add 2 parameters.
|
Wouldn't make sense because each job writes to it's own console, you couldn't watch 2 consoles at once.
Think of jobs as an array where you can get 1 item at a time, add 1 at a time, or remove 1 at a time.
https://www.redhat.com/sysadmin/jobs-bg-fg
| Bring multiple background jobs to foreground |
1,525,494,603,000 |
I'm running a long-running pipeline from bash, in the background:
find / -size +500M -name '*.txt' -mtime +90 |
xargs -n1 gzip -v9 &
The 2nd stage of the pipeline takes a long time to complete (hours) since there are several big+old files.
In contrast, the 1st part of the pipeline completes immediately, and since ... |
FWIW, I can reproduce your case with:
rhel8$ /bin/jobs(){ jobs -l; }
rhel8$ sleep 1 | sleep 3600 &
[1] 2611
rhel8$ sleep 2
rhel8$ jobs
[1]+ Running sleep 1 | sleep 3600 &
rhel8$ /bin/jobs
[1]+ 2610 Running sleep 1
2611 Running | sleep 3600 &
rhel8$ pgrep 2610
... | 'jobs' shows a no longer existing process as running |
1,525,494,603,000 |
python3 -i test.py opens an interactive python shell after running test.py. However, if I try to run it in the background with python3 -i test.py &
the job stops automatically with a ^C and shows
[4]+ Stopped python3 -i test.py
, and I can't access python's interactive shell (with the variables from... |
That happens because the Python interpreter in background "competes" the prompt with the command-line shell as soon as it finishes executing the test.py program.
Naturally Python loses that "battle" because it is not the one allowed to go interactive at that moment. However it gets stopped a bit too late, enough to le... | Opening interactive python shell after running python script in background |
1,525,494,603,000 |
I do some scientific calculation on a PC(in fact several PCs) and I want to know how many jobs should I submit one time. lscpu shows:
CPU(s): 8
On-line CPU(s) list: 0-7
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 1
The ambiguity is 'Thread'. I searched the net and learned... |
If this PC has an Intel CPU, then the Thread(s) per core most certainly indicates hyper-threading.
https://en.wikipedia.org/wiki/Hyper-threading
For each processor core that is physically present, the operating system addresses two virtual (logical) cores and shares the workload between them when possible. The main f... | How many CPU do I have and how many jobs should I submit? |
1,525,494,603,000 |
I downloaded a directory of files, directory.1
containing the files
file.1
file.2
file.3
I move file.2 by
mv file.2 ../another.directory &
My problem is I want to get rid of directory.1 and the contents but I have to wait for my job to finish. Is there a way around this? Or a quick way to do a..
rm -r directory.1
... |
You can just aggregate the two commands with &&:
cd ..
mv directory.1/file.2 another.directory && rm -r directory.1 &
| How can you move a file as a background job and delete all other files and the directory before waiting for the job to finish? |
1,525,494,603,000 |
I don't know what exactly is JID (job ID) and how it is assigned. What is it's relation to PID and how does one number affect the size of the other in any way?
|
There are no relations between a PID and a job ID on shells I have used (bash, dash and zsh).
However, a shell job is a child process of the shell, whereas PID 1 (init) is the ancestor of all processes, including the shell. Therefore a process with job id 1 will always have a PID greater than the job ID.
The assignmen... | What is JID (job ID) and is it always smaller than PID? [closed] |
1,517,904,856,000 |
I'm looking for a way, to simply print the last X lines from a systemctl service in Debian. I would like to install this code into a script, which uses the printed and latest log entries. I've found this post but I wasn't able to modify it for my purposes.
Currently I'm using this code, which is just giving me a smal... |
journalctl --unit=my.service -n 100 --no-pager
| How to see the latest x lines from systemctl service log |
1,517,904,856,000 |
If I type sudo journalctl I get the system journal in some kind of a reader. Pressing j and k works like in Vi but G does not go to the end of the file. In fact, if press G, the stream freezes and I have forcibly terminate it.
No mention of using the reader is in the man page for journalctl.
|
that "reader" is just less.
No mention of using the reader is in the man page for journalctl.
err, said man page:
The output is paged through `less` by default,
but:
but G does not go to the end of the file. In fact, if press G, the stream freezes and I have forcibly terminate it.
G works beautifully, the log i... | How do you go to the end of the file in journalctl? |
1,517,904,856,000 |
I am completely new to Linux.
I know that dmesg and journalctl record commands invoked by my operating-system, but why do 2 recorders exist, what types of messages should I expect to see within each of them, and what are the differences in their life cycles?
|
They are two totally different things.
On most systems that I'm aware of that has dmesg, it is sometimes a command and sometimes a log file in /var/log, and may be both. The log contains messages produced by the kernel. This will usually include the various device probe messages during the boot sequence as well as an... | What is the difference between dmesg and journalctl [closed] |
1,517,904,856,000 |
I want to watch output from a systemd service on CentOS as if I have started this service from console. Yes, I can see output with journalctl, but it doesn't scroll to the bottom automatically. So how can I watch live output from service?
|
journalctl -f -u mystuff.service
It's in the manual:
-f, --follow
Show only the most recent journal entries, and continuously print new entries as they are appended to the
journal.
and
-u, --unit=UNIT|PATTERN
Show messages for the specified systemd unit UNIT (such as a servic... | How to watch output from systemd service? |
1,517,904,856,000 |
I'm trying to get the last few lines from journalctl so I can feed them into my conky. However journalctl by default provides too much crap that wastes space: With journalctl -u PROCESS -n 5 --no-pager -l I get entries like:
DATE TIME HOSTNAME PROCESS: MESSAGE
I want to print only TIME MESSAGE. How can I do that?
The... |
EDIT: Please refer to this answer instead. The below answer is kept only for posterity.
This seems to have been implemented in 2018, see this PR. With version 236 and above it looks like you can use --output-fields=, described in --help. Check your version with systemctl --version, my CentOS 7 currently (in 2019) run... | Print only timestamp and message in journalctl |
1,517,904,856,000 |
Using sudo journalctl -u {service} I can see the log of specific service.
How to find the associated log file?
What is the best way to monitor a log file programmatically? (I mean a program the react based on something appears in the log file)
|
Systems with s6, runit, perp, nosh, daemontools-encore, et al. doing the service management work this way. Each main service has an individual associated set of log files that can be monitored individually, and a decentralized logging mechanism.
systemd however does not work this way. There is no individual "associa... | Where to find the log file of specific service |
1,517,904,856,000 |
Where can I find gnome-shell error (or debug) log?
I'm interested in mutter error/warning messages since I have a GLX problem I need to debug and I believe the key could be in gnome-shell's messages.
|
I'd start with journald's logs. Try one of these:
$ journalctl /usr/bin/gnome-shell
$ journalctl /usr/bin/gnome-session
If the logs are not there then try this:
$ journalctl -xe
Googling I did find this thread titled: gnome-session logging which did have several examples that worked when I tried them on an Ubuntu 16... | gnome-shell error log |
1,517,904,856,000 |
last three days I am experiencing random freezes. If i am looking on youtube when this happens Audio keeps playing but screen is froze and keyboard or cursor do not do anything.
I trying to look in sudo journalctl and this is what I found:
led 04 10:44:02 arch-thinkpad kernel: i915 0000:00:02.0: [drm] *ERROR* Atomic u... |
5.10.15 doesn't solve this problem. I still have same error. Intel bugs are really annoying since kernel > 4.19.85 (November 2019 !)
As a workaround, i915 guc need to be enable as mentionned in Archlinux Wiki : https://wiki.archlinux.org/index.php/Intel_graphics#Enable_GuC_/_HuC_firmware_loading and loaded before othe... | Arch linux randomly freezes after updating to kernel 5.10 |
1,517,904,856,000 |
journalctl --boot prints log lines since boot and journalctl --follow prints the last 10 lines of the log and then follows it. But journalctl --boot --follow doesn't work like I expect it to. Rather than printing all the journal lines since boot and then following the journal it just ignores --boot flag. Swapping the ... |
Adding --lines=all does the trick - rather than overriding --boot they work together to follow lines since boot.
journalctl --boot --lines=all --follow
| How to follow journalctl since boot? |
1,517,904,856,000 |
I'm having a systemd service defined as follows, that works fine:
[Unit]
Description=my service
After=network.target
[Service]
User=myuser
Group=mygroup
WorkingDirectory=/home/myuser/myapp
Environment="PATH=/home/myuser/myapp/.venv/bin"
ExecStart=/home/myuser/myapp/.venv/bin/python3 /home/myuser/myapp/run.py
Restart=... |
The problem is actually with buffering from the Flask application and not with how systemd or journald are ingesting those logs.
This can be counter-intuitive, since as you mentioned, running python3 run.py directly on the command-line works and shows logs properly and also timestamps look correct on the logs.
The for... | Getting systemd service logs faster from my service |
1,517,904,856,000 |
I have a process which is started by systemd - lets call it A. This process spawns numerous child processes - lets just take one and call it B.
This is a C++ application. When you print to std::cout the output is captured by systemd and can be viewed with the journalctl command.
Whenever a message is printed to std::c... |
I've found the answer. You need to use sd_journal_send() from systemd/sd-journal.h.
You can also use the SYSLOG_IDENTIFIER and SYSLOG_PID tags to customise what is used.
More info on the available tags can be found here.
Example:
std::string sysLogIdentifier("SYSLOG_IDENTIFIER=");
sysLogIdentifier += program_invocatio... | systemd - journalctl output always shows the parent process name in log entries |
1,517,904,856,000 |
How can I configure the journalctl output to use a specified date format?
I know I can parse out the line and convert to a date format, but I'm hoping to see the log lines with the ISO format.
|
The -o option allows the timestamp formatting to be chosen among a few options, including ISO format (e.g. 2022-08-04T17:45:08+0200) with
journalctl -o short-iso
or
journalctl -o short-iso-precise
if you need milliseconds.
| journalctl set default datetime format |
1,517,904,856,000 |
Is there a canonical way to get all the logs from journalctl since a service was last restarted? What I want to do is restart a service and immediately see all the logs since I initiated the restart.
I came up with:
$ unit=prometheus
$ sudo systemctl restart $unit
$ since=$(systemctl show $unit | grep StateChangeTimes... |
You can use the invocation id, which is a unique identifier for a specific run of a service unit.
It was introduced in systemd v232, so you need at least that version of systemd for this to work.
To get the invocation id of the current run of the service:
$ unit=prometheus
$ systemctl show -p InvocationID --value "$un... | Show journal logs from the time a service was restarted |
1,517,904,856,000 |
An interesting annoyance that just plagued a coworker:
If you less a file that's being appended to, you can hit shift-f to start following the output stream in real time. Then, to stop following the output, you hit ctrl-c, after which you can navigate and search the file as usual.
This does not work when using journal... |
As answered over on ServerFault, this is because less is invoked with the K flag, which causes it to die upon recieving a ^C character, rather than returning to its command prompt.
To remedy this, export the variable SYSTEMD_LESS="FRSXM" into your environment. This is the standard set of flags that systemd passes to l... | Breaking out of follow mode with less and journalctl |
1,517,904,856,000 |
I'm using less to view my journalctl logs because it's more convenient. It doesn't clutter the console window with logs after you exit less and you can scroll using your mouse wheel.
journalctl --unit xyz | less +G
But it's very annoying that I cannot refresh the logs. Is there a way to do that with less? Using Shift... |
But it's very annoying that I cannot refresh the logs. Is there a way to do that with less? Using Shift + F doesn't work.
You might be looking for journalctl's, --follow/-f. That cancels the use of a pager by journalctl, so I guess you need to add it.
journalctl -fu xyz | less
Then less's Shift+F works to see new e... | Is it possible to dynamically refresh journalctl with less? |
1,517,904,856,000 |
How do I grant read-only permission to somegroup to read the system journal? (I'm on Debian10 buster).
$ journalctl
Hint: You are currently not seeing messages from other users and the system.
Users in the 'systemd-journal' group can see all messages. Pass -q to
turn off this notice.
No journal files w... |
tl;dr
Create the following file:
# /etc/tmpfiles.d/somegroup_journal.conf
#Type Path Mode User Group Age Argument
a+ /run/log/journal - - - - d:group:somegroup:r-x
a+ /run/log/journal - - - - group:somegroup:r-x
a+ /run/log/jour... | How to let a specific group have read-access to systemd's journal? |
1,517,904,856,000 |
I am using Yocto to produce a custom image for a small embedded Linux system with SystemD Version 241. The root file system is Read-Only. I am using bind mounts and overlayfs to make the /var/log/journal directory exist on a separate Read/Write partition. I have a problem where systemd-journald gets "Amnesia" and does... |
I have been fighting the same problem for quite a while now. I have a Yocto-based distro where I have a read-only rootfs and the /var/log folder is mounted in a different partition using volatile-binds. Once I got journald to log to the new partition I noticed the same thing, journalctl --list-boots would only show th... | systemd-journald persistent logs do not work with bind mount /var/log |
1,517,904,856,000 |
I've a problem, every time I close the lid the laptop wakes up 2 seconds after (with the lid still closed)
systemctl suspend/hibernates comes to the same result
The problem happens on every linux distros (Ubuntu, ElementaryOS, debian, ...)
Here is my journalctl when closing the lid
-- Logs begin at Sun 2018-06-10 12:0... |
I've finally find the error, my laptop is an HP Spectre 13 v001nf.
For future users:
You should add this in your rc.local (if you have systemd add this has a service)
#!/bin/sh -e
for device in XHC PWRB
do
if grep -q "$device.*enabled" /proc/acpi/wakeup
then
echo $device > /proc/acpi/wa... | Laptop wake up when lid is closed |
1,517,904,856,000 |
I have a vpn service unit for which I can view the logs with...
journalctl -u vpn
I also have a script that interacts with the vpn manually and is logged to journal with...
exec > >(systemd-cat -t vpn.sh) 2>&1
and I can view the logs with...
journalctl -t vpn.sh
I tried viewing both logs with...
journalctl -u vpn -... |
TL;DR: This will work:
$ journalctl _SYSTEMD_UNIT=vpn.service + SYSLOG_IDENTIFIER=vpn.sh
You can use + to connect two sets of connections and look for journal log lines that match either expression. (This is documented in the man page of journalctl.)
In order to do that, you need to refer to them by their proper fiel... | How can I view journalctl logs by unit and identifier with one command? |
1,517,904,856,000 |
I have a dark background for my console so there's quite a bit of journalctl output that is unreadable.
I see lots of information about how to add color! But how do I completely disable it?
|
you can disable colour in journalctl like so;
SYSTEMD_COLORS=false journalctl
you could then add it to your ~/.bashrc, exporting the env variable;
export SYSTEMD_COLORS=false
That will be global though and may effect other systemd related things.
I guess a more direct solution would be to add an alias to your ~/.bas... | journalctl output disable colorization |
1,517,904,856,000 |
On my archlinux installation, I realised that flushing the journal logs to disk by the systemd-journal-flush service significantly prolongs the boot process and masking the service improves boot time. Can I permanently mask the service and run journalctl --flush later when the computer is idle to flush the journal log... |
Others point out that running journald without any persistent logs, is an option. This approach is documented without any particular warnings, and is used on large numbers of systems. Fedora started with no persistent journal plus a syslog daemon, and Debian still defaults that way.
So there's no reason to expect a ... | Can I mask the systemd-journal-flush service and run journalctl --flush later manually? |
1,517,904,856,000 |
The system has very old boots (2 and 3 years old), which are not recycled and I haven't been able to vacuum them:
$ journalctl --list-boots --no-pager
-16 53baf678f0d749d6b390afea4a3ef96b Wed 2014-04-02 22:07:26 IDT—Wed 2014-04-02 22:46:08 IDT
-15 60a54132f5c8450d9b33a77819a037d1 Thu 2014-04-03 00:04:50 IDT—Thu 2014-0... |
The new binary logs on Linux operating systems do not work in the way that the old binary logs did.
The old binary logs were /var/log/wtmp and /var/log/btmp. At system bootstrap an entry would be written to wtmp with the username reboot, and at shutdown an entry would be written to wtmp with the username shutdown. F... | journalctl shows very old boots which are not recycled |
1,517,904,856,000 |
Here's a test script I used:
last_reboot=$(last reboot | grep 'still running' | awk '{for (i=5; i<=NF; i++) printf $i FS}' | awk '{for (i=1; i<=NF - 2; i++) printf $i FS}')
if [ "$last_reboot" ]; then
date -d "$last_reboot" '+last reboot: %Y-%m-%d'
fi
days=$(uptime | awk '{print $3}')
hours=$(uptime | awk '{print... |
The new binary logs on Linux operating systems do not work in the way that the old binary logs did.
The old binary logs were /var/log/wtmp and /var/log/btmp. At system bootstrap an entry would be written to wtmp with the username reboot, and at shutdown an entry would be written to wtmp with the username shutdown. F... | Why `journalctl --list-boots` doesn't match what `uptime` and `who -b` report? |
1,517,904,856,000 |
With normal syslog I can go to /var/log and run tail -F *log if I am not sure which log something is logged in.
Is there an equivalent for systemd?
Background
I am trying to debug a server. It crashes without leaving a trace. I am hoping that using the systemd version of tail -f *log that I can see log messages that a... |
What you want to use is the journalctl command. For example, if I want to get updated log entries on the service vmware, I would run this (f = follow, u = unit/service name):
journalctl -f -u vmware.service
Here's how you can get the full system journal. I use this command for my updated system logs (f = follow, x = ... | 'tail -F *.log' but with systemd |
1,517,904,856,000 |
One of our Ubuntu 18.04 hosts was caught with 12 GB of *.journal files, far more than intended. Attempting to find out if they were worth keeping, I ran
journalctl --file $f
on each file older than today; which always resulted in either Failed to open files or --- No entries ---.
Am I correct to conclude that such fi... |
First of all Journal is a logging system and is part of systemd. Their existence is crucial when you need to know what happened.
As mentioned here, journalctl --file isn't that usable.
As the journal files are rotated periodically, this form is not really usable for viewing complete journals.
Now, whether you consid... | How to detect and clean up junk journal files? |
1,517,904,856,000 |
Currently my systemd journal is filling up with messages of the form:
Feb 01 16:40:31 host systemd[1]: Got message type=method_call
sender=:1.58666 destination=org.freedesktop.systemd1 object=/org
/freedesktop/systemd1 interface=org.freedesktop.DBus.Properties member=Get
cookie=2 reply_cookie=0 error=n/a
The only id... |
There is a mapping between a unique connection name
and process accessible through busctl.
If it remains stable for a few seconds you could try your luck in trying to catch it as it occurs.
journalctl -f | \
while read line ; do
echo "$line" | grep "sender=:"
if [ $? = 0 ]
then
... | How do I work out which process/service/program is sending systemd dbus messages? |
1,517,904,856,000 |
I'm using Ubuntu 16.04 and I am seeing some strange behavior when analyzing journalctl logs.
Here's unfiltered output (I used json output to hopefully include all relevant fields):
$ journalctl -o json-pretty --since "2018-01-11 12:00:00" --until "2018-01-11 12:00:05"
{
"__CURSOR" : "s=bac060082d1c447a972958f176cdcec7... |
Turns out I was using old version of systemd - 229, while latest is 236, and using newer journalctl fixes this problem. Unfortunately, 229 is the latest available systemd version for 16.04 LTS, so I do not see a sensible workaround for the issue (apart from building latest systemd in user-space and using freshly built... | Why journalctl does not display log message if I use filtering by unit? |
1,517,904,856,000 |
I'm using RHEL 7, and would like to know if and when a particular service 'myservice.service' went inactive. Unfortunately, using:
journalctl -u myservice.service
only seems to show output from my actual service, but at some point, the output stopped, and I don't know if that's due to:
the service being shut down, o... |
You can check for information in the system logs.
on redhat:
/var/log/messages
on debian based distributions :
/var/log/syslog
You should also look for the logs of your particular service, it could be into something like
/var/log/<yourservice>.log
All those log are rotated so you can find older information ins... | How to know exactly when a Linux service went inactive? |
1,517,904,856,000 |
Some error messages in journalctl show up in red and white. If I'm authoring my own systemd service, how can I format my messages such that they show up in red or white. It's a nice way of having errors stand out.
|
It's the priority that determines how journalctl displays messages.
Based on a quick test with logger :
Messages of priority debug and info are displayed "normally".
Messages of priority notice and warning are displayed in bold white.
Messages of priority err, crit, alert, emerg are displayed in bold red.
Edit:
To a... | How do I make journalctl messages show up in red? |
1,517,904,856,000 |
I have some files in my /var/log/journal/f7e928ba68a9449e85bd828252981fc6/ that have a .journal~ extension.
Can I remove these?
example:
-rw-r-----+ 1 root systemd-journal 16777216 Dec 21 08:46 [email protected]~
Can I delete these files?
|
From man systemd-journald:
FILES
/run/log/journal/machine-id/*.journal, /run/log/journal/machine-id/*.journal~, /var/log/journal/machine-id/*.journal, /var/log/journal/machine-id/*.journal~
systemd-journald writes entries to files in /run/log/journal/machine-id/ or /var/log/journal/machine-id/ with the ".journal" s... | What are the .journal files that have a ~ on the end? |
1,517,904,856,000 |
I am trying to create a service to run on boot. The service is a program I wrote in C++ and compiled and is located in my users home directory. The program opens some UDP sockets and sits in an infinite loop so it does not exit automatically. I can run the program manually and everything works as expected but when I r... |
SELinux is preventing your program to run: the AVC denial states type=AVC msg=audit(08/16/2021 20:14:04.216:698) : avc: denied { execute } for pid=2568 comm=(ster_myservice) name=program dev="dm-2" ino=137 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0.
T... | Systemd Service Failing with exit-code status=203/EXEC |
1,517,904,856,000 |
When I search in journalctl with / the search is case sensitive unless I switch to case insensitive with -i first.
How can I configure journalctl so that searches are case insensitive by default?
|
For some reason journalctl does not use the LESS environment variable but uses SYSTEMD_LESS:
$SYSTEMD_LESS
Override the options passed to less (by default "FRSXMK").
Since less is already the default pager you can configure
export SYSTEMD_LESS=-i
or use the same options as less:
export SYSTEMD_LESS="$LESS"... | journalctl search case insensitive |
1,586,628,012,000 |
In the past few days I have had a message in the system log/journal over a thousand times within a second. How can I find out where it originated?
# journalctl --system | grep "testing the buffer" | uniq --count
1522 Apr 06 13:49:31 laptop unknown: testing the buffer
So, 1522 times the same message by "unknown". Is... |
Seems to be related to latest kernel (5.6.x).
If you tail the journal with verbose level
sudo journalctl -f -o verbose
You can see _TRANSPORT=kernel
Sun 2020-04-12 09:32:38.852081 CEST [s=ca0e47a50a2047e483013075418f4a72;i=1d58f89;b=343f4563d34649baad6f57aacc0320a1;m=e9cad4480;t=5a312f895b1f1;x=16d4d0c3d713857c]
... | How can find out where a system message originates ("testing the buffer" in dmesg / journalctl / messages)? |
1,586,628,012,000 |
I have a simple Python snippet managed by a systemd service which logs to the rsysogd daemon where I've defined a configuration file to put it to a syslog server with a format I've defined. This is working fine so far.
In the code below, I'm passing the argument as the string I want to log on the server. I'm using thi... |
I have a simple Python snippet managed by a systemd service which logs to the rsys[l]ogd daemon […]
No you haven't.
What you have is a service that logs to the systemd journal. The server listening on the well-known /dev/log socket that your Python program is talking to is not rsyslogd. It is systemd-journald. ... | Prevent syslogs from being logged under journalctl |
1,586,628,012,000 |
journalctl has the -o short-unix flag that I can use to change the output date format on stuff like -t systemd-sleep.
But the only way I've found to list boots is --list-boots, and this doesn't seem to obey the -o flag.
Is there a way to make journalctl list boots with unix timestamps? Since systemd is here to stay I ... |
You can however convert those fields into unix timestamps.
I.e:
journalctl --list-boots | awk '{ d2ts="date -d \""$3" "$4" " $5"\" +%s"; d2ts | getline $(NF+1); close(d2ts)} 1'
| List boots with unix timestamps via journalctl |
1,586,628,012,000 |
I've noticed, on machines where the journalctl logs are saved on disk, that on a reboot, I get a line between the message before and after the reboot happened like so:
blah
blah
blah
-- Reboot --
blah
blah
blah
How does journalctl know to add that line at that location?
|
journalctl keeps track of the boot_id attached to logs, and when that changes, indicates that the system rebooted.
The boot_id is generated by the kernel, and can be retrieved from /proc/sys/kernel/random/boot_id.
| How is journalctl able to add the line with the "-- Reboot --" log message? |
1,586,628,012,000 |
I would like to show only crit and info and nothing in between.
I tried:
journalctl -p 2..2 -p 6..6
But it doesn't work. The second argument seems to override the first.
The following code produces a syntax error:
journalctl -p 2,6
How can I retrieve only two priorities without any values in between?
I'm searching f... |
Specify it as a raw filter, as you already know the fields:
journalctl PRIORITY=2 + PRIORITY=6
While the filter syntax is not very expressive, it does support one level of 'OR' operation using +. (For example, journalctl A B C + D E means "(A && B && C) || (D && E)".)
| How to tell journalctl do display exactly two priorities? |
1,586,628,012,000 |
What is the cause of the error ”Journal header limits reached or header out-of-date, rotating” and what can be done to fix it?
journalctl (systemd-journald[###]) reports journal errors:
Data hash table of /run/log/journal/####/system.journal has a fill level at 75.1 (3273 of 4359 items, 2510848 file size, 767 byte... |
Journal header limits reached or header out-of-date, rotating is not an error, it's an informational message.
It means systemd-journald adheres to the journal limit you've set.
| How to resolve journalctl error - journal header limits reached or header out of date |
1,586,628,012,000 |
I have an app registered as a service in Ubuntu 16.04
If I type:
journalctl -u myapp.service
I can see the logs for my app.
I am moving my app to a new VM where the same service will be in place. Is it possible to migrate the log files to the new VM so that if I type journalctl -u myapp.service it will show all my ol... |
All entries for which you will find a relation using journalctl -u <myapp.service> correspond to the contents of the systemd journal for a given host. HOWEVER (from man journalctl):
Output is interleaved from all accessible journal files, whether they are rotated or currently being written, and regardless of whether... | Can I migrate ubuntu journald logs? |
1,586,628,012,000 |
What should I look for in the systemd journal to find when the latest boot happened?
|
I would use an empty -b,--boot option to journalctl in order to request "the current boot", then -n 0 to request zero lines of output, which leaves just the header:
journalctl -b -n 0
Example output:
-- Logs begin at Wed 2021-02-10 17:46:08 PST, end at Thu 2021-02-11 15:36:01 PST. --
Or if the -n 0 fails to output t... | What will a boot look like in the systemd journal (journalctl)? |
1,586,628,012,000 |
Is there a reasonable procedure for a system administrator to view all the fsck messages?
On my current Fedora 29 system, I can view all the fsck messages from my current boot like this:
sudo journalctl -b /usr/lib/systemd/systemd-fsck
However, it is a hack that assumes fsck writes messages to stdout / stderr. It d... |
sudo journalctl -b -u 'systemd-fsck*'
The credit for this answer belongs here: https://unix.stackexchange.com/a/436033/29483
A second answer on the linked question notes that this method will not work on all systems, even if the system uses systemd. One reason is if the initramfs, which runs fsck on the root files... | How to show journal messages from all `fsck` units |
1,586,628,012,000 |
While looking through some archived journal files from another machine, I noticed that some log entries have different __BOOT_ID values with extremely narrow time gaps in between. For an example, log entries that are milliseconds apart would have different __BOOT_ID values. This should not be possible as the machines ... |
I don't think the boot ID is actually changing that rapidly. I think you're viewing logs from several different boots at once, and they're getting mixed together.
This can happen if your system doesn't have a battery-powered real-time clock.
journalctl uses the wall clock time to sort log messages that came from diff... | Rapidly changing boot_id values in systemd |
1,586,628,012,000 |
Everything worked fine last time I used Solus, and now I cannot boot because of the error below.
Let's try to solve it without using a live USB.
**Failed to start File System Check on /dev/disk/by-partuuid/5ff8cfe6-53e1-43b1-9275-dc6f24ad812a**
|
According to the man page, fsck's error code 4 means "Filesystem errors left uncorrected".
This is not good. It means that the file system is corrupted beyond what is safe to automatically repair on boot, so manual intervention is required.
As the error message on your screen says, you need to manually run fsck to at... | Solus distro is not booting anymore |
1,586,628,012,000 |
I was doing the recommended maintenance work as advised here. I ran the command sudo journalctl -p 3 -xb, I see that tracker-extract is repeatedly crashing and dumping core. I am not sure what to do. Please help me.
Followig is a part of output generated by sudo journalctl -p 3 -xb.
I am using Arch Linux, with Gnome ... |
Probably during the migration process from tracker to track3 something goes wrong.
Clean tracker database ($ tracker3 reset) and any leftover file ($ rm -rf ~/.cache/tracker{,3})
| tracker-extract repeatedly core dumping and crashing |
1,586,628,012,000 |
Looking through the Archwiki on journalctl and systemd I do not see a means of configuring the system log to display in a 12 hour format with am and pm. The 24 hour format works fine; however, I need to convert from 24 hour to 12 hour to check the log against the current system time. Is there a systemd config file or... |
There's no such option. The time formatting options are limited (either locale-dependent, but still 24-hour, or Unix timestamps, or ISO 8601 timestamps).
I'd just check the current date in 24-hour format (and put it in a prompt or a widget somewhere):
% date +%T
18:40:59
But you can also parse the journalctl outpu... | journalctl 12 hour format? |
1,586,628,012,000 |
When cron runs
0 16 * * * journalctl --vacuum-time=10d
I get an email with the content like
Vacuuming done, freed 0B of archived journals from /var/log/journal.
Vacuuming done, freed 0B of archived journals from /var/log/journal/68eb3115209f4deb876284bab504772b.
Vacuuming done, freed 0B of archived journals... |
Simplest thing to do is to pipe through 2>&1 | grep -v 'freed 0B'
If cron runs a command that produces zero lines of output, then cron will not send an email.
| suppress cron emails from cleaning systemlog if 0B were cleaned |
1,586,628,012,000 |
Well, the answer is simple - using command "journalctl".
But let me describe the problem first,
I encountered an ubuntu server crash event and some log/.journal files were extracted successfully, and the next way to deal with this event is to read/analyze these files.
There were 2 requests being discussed:
A. How to r... |
Now I discovered that when and after using command "cat" to read .journal file, gibberish will appear on the console display
Indeed. It's a binary file
and I have no choice but to reboot to clear out the mess.
This is not correct. You can usually fix this by using the Control-j, reset, Control-j combination (see h... | Commands to read the content of .journal file? |
1,586,628,012,000 |
My system failed to boot several times today.
After completely disconnecting it from power, I managed to get it back on, luckily, but I'd like to comprehend what has happened.
From a user's point of view, it was like this:
I turn on the PC, the fans are noisier than usual and the boot process would get stuck sometimes... |
You have a modern multi-core processor and your distribution uses systemd. As a result, at boot time, many things will happen in parallel, sometimes with no fixed ordering. Some of the log messages might be slightly out of order with each other, if they used different routes (native systemd journaling vs. the kernel's... | How to read these journal entries after failed boot? |
1,586,628,012,000 |
My system freezes and the only solution is to force shutdown it. I'm not sure but maybe the problem is due chromium-vaapi , any missconfiguration or something.
I'm in 5.4.13-arch1-1 #1 SMP PREEMPT.
Here my journalctl with the freeze.
Thanks a lot.
|
Actually, this is a GPU driver bug. It's already in your paste.
ene 22 18:59:01 dlag-pc kernel: i915 0000:00:02.0: GPU HANG: ecode 9:1:0x00000000, hang on rcs0
ene 22 18:59:01 dlag-pc kernel: GPU hangs can indicate a bug anywhere in the entire gfx stack, including userspace.
ene 22 18:59:01 dlag-pc kernel: Please file... | System completly freezes often (maybe chromium-vaapi) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.