Skip to main content

Questions tagged [exec]

The exec() family of functions replaces the current process image with a new process image, retaining the pid and pipes of the old process. This tag is also used for the shell built-in which can be used to replace the current shell with a program or various redirection-related stuff.

Filter by
Sorted by
Tagged with
0 votes
0 answers
24 views

Using systemd + docker exec to manage processes within a single container

As of today, I have many systemd services where each of them runs a command using docker run. The same docker is used for all services. I've noticed that each container that runs, takes about 0.7% of ...
Omer's user avatar
  • 101
0 votes
0 answers
56 views

Understanding AFL behaviour for fork and execv; Why `/proc/<pid>/maps` does not show the loaded binary

TL;DR Why process map in /proc/<pid>/maps does not show where the executed binary is loaded? I am trying to do some post-mortem analysis of the fuzzed program once it finishes. Basically what I ...
sorin the turtle's user avatar
2 votes
1 answer
101 views

How to pass a parameter to a command that's being executed by exec in bash?

I'm trying to start a subprocess with a unique process name from a bash script. This works: bash -c "exec -a MyUniqueProcessName './start_service' &" but my problem is that I want to ...
Adam Arold's user avatar
4 votes
1 answer
145 views

POSIX Shell: `exec` with changed arg0

I want to exec a program and control it's arguments including arg0 and environment. Using C I could go for execve. Can I do this in POSIX shell?
Patrick Böker's user avatar
0 votes
1 answer
104 views

How to perform strace on shell without changing your current shell?

I use strace to trace the behavior of a bash process. The purpose is to find out the order bash loads its configuration files. I am running the following command under zsh: strace -e openat bash ...
Visrut's user avatar
  • 137
15 votes
1 answer
1k views

Is the behavior of bash -c "<single command>" documented?

It's quite known that when running bash -c "COMMAND" (at least in the common versions in Linux) when there's a single command without any metacharacter (except for space, tab or newline), ...
aviro's user avatar
  • 5,912
0 votes
2 answers
40 views

Creating an option for 'exec > >(tee -ia $OUT)' to skip stdout

I'm trying to modify a script that uses the following: # first portion of script # ... exec > >(tee -ia $OUT) # ... # second portion of script The problem I have with this script is that it ...
Seamus's user avatar
  • 3,087
0 votes
1 answer
53 views

How to execute a subshell directly

I have this: timeout 25 bash -c ' for i in {1..9}; do if read line < "$my_fifo"; then if test "$line" != "0"; then exit 0; ...
Alexander Mills's user avatar
2 votes
1 answer
197 views

How to stop redirection via exec

I want to redirect some output of a script to a file. REDIRECT_FILE="foo.txt" echo to console # starting redirect exec > $REDIRECT_FILE echo to file echo ... echo ... # stop redirect ...
Andy A.'s user avatar
  • 207
0 votes
0 answers
34 views

Forward data incoming from another machine using srsUE

I have a srsRAN setup which includes srsUE (srsRAN_4G), srsgnb (srsRAN_Project) and 5Gcore (open5gs) everything running in the same Ubuntu machine. I can send data from the UE to the core by using the ...
Raúl Parada Medina's user avatar
0 votes
0 answers
51 views

How to regain script interactivity when `... | bash` best practices?

Let's say we have a simple script named question: #!/bin/bash read -rp "What's your name?" ans echo "Your name is $ans" Let's use cat for our example cat question | bash We ...
punkbit's user avatar
  • 111
0 votes
1 answer
82 views

How is this exec command supposed to work in this context?

I'm working through a textbook on UNIX system administration. Chapter 3 of "Unix Third Edition" by a Syed Mansoor. Chapter 13 has the following example of exec usage which is straightforward ...
Anthony De Vellis's user avatar
0 votes
1 answer
139 views

how to bring exec $@ process in foreground

I want to know how docker entry point process which has started with exec $@ and has PID 1 how to bring that in foreground I tried exec $@ & but its not working, My use case: I want to terminate ...
Samurai's user avatar
  • 55
0 votes
2 answers
264 views

missing argument to `-exec' error when executing Shell script but runs fine on command lines

I have this Shell script here: ### # Create a folder dynamically mkdir archived_PA_"$(date -d "6 months ago - 1 day" +%Y-%m-%d)"_"$(date -d "1 day ago" +%Y-%m-%d)&...
Anna Nguyen's user avatar
1 vote
1 answer
81 views

How to load android binaries in Debian environment?

I am trying to run adbd from within a chrooted environment. I can run it fine with Android's LD_LIBRARY_PATH=$PWD ./linker64 $PWD/adbd. When I try to run ./adbd I get: bash: ./adbd: cannot execute: ...
Bret Joseph's user avatar
1 vote
0 answers
28 views

Why does subcommand take the PID of parent when I don't use exec [duplicate]

I executed bash -c "ps && ps" and got the following output: PID TTY TIME CMD 25544 pts/0 00:00:00 bash 26562 pts/0 00:00:00 bash 26563 pts/0 00:00:00 ps PID TTY ...
user1335014's user avatar
1 vote
1 answer
215 views

How to display file and folder properties from search

I thought this would be easy and there are a lot of somewhat close threads on the internet, but nothing quite right. I want to use fd (simple find command) to display just file name and file size (...
1toneboy's user avatar
  • 441
1 vote
2 answers
704 views

Capture and redirect stdin (user input) for runtime of script

I can redirect the stdout/stderr of everything in a script like this: #!/bin/bash exec > stdout_file echo example But now I want the stdin of the whole script to be written into a file. I tried it ...
Nudin's user avatar
  • 111
1 vote
1 answer
467 views

Log all commands executed regardless of shell?

Suppose a user runs the following command: zcat file.gz | grep something | gzip > grepped.gz I'm looking for a kernel feature (a BPF filter perhaps?) that would note all of the execves, chain ...
d33tah's user avatar
  • 1,361
-1 votes
1 answer
75 views

Why 'helix-23.03-aarch64.AppImage' [in debian on x86_64 in Macbook Pro] is giving 'Exec format error'?

It is on debian on x86_64 me@debian:~/bin$ chmod a+x helix-23.03-aarch64.AppImage me@debian:~/bin$ ./helix-23.03-aarch64.AppImage /tmp/.mount_helix-RyzFyw/AppRun: 4: exec: /tmp/.mount_helix-RyzFyw/usr/...
tom_kp's user avatar
  • 43
0 votes
3 answers
90 views

bash -c "exec -a myProcessName ./script.sh &" doesn't send that script into backgound

From a bash script, I need to start three processes and put to each of these processes a name, in order to be able to stop them in a later stop command. # Démarrer les applications eco emploi : ...
Marc Le Bihan's user avatar
2 votes
1 answer
182 views

Why does the provided command as a parameter not run in a loop in my script?

I made a simple script that executed a command every minute: #!/usr/bin/env sh while true; do exec "$@" sleep 60 done The idea is to make it as a Docker entrypoint that will allow ...
Dimitrios Desyllas's user avatar
1 vote
1 answer
2k views

Does running exec command preserves environment variables of the calling shell? If so, why?

From my understanding exec command replaces the calling shell program with the command without forking a child process. Also if I understand correctly exported variables are the ones that are passed ...
Almaz Kharrasov's user avatar
0 votes
1 answer
423 views

Help with -maxdepth in 'find -exec mv' command line

I'm working on a sorting/filtering cron script to process incoming files based on a set of constant strings (logfile, history, dataset, etc). The files to be sorted all sit under a common folder, some ...
graphics.guy's user avatar
0 votes
1 answer
908 views

"exec" is exiting the script and not proceeding to next step

We are trying to capture return code of exec command but once the command is executed the script is getting exit without proceeding to next lines. exec /bin/sh -c $command > log.txt rc=$? if [ $rc -...
Arya's user avatar
  • 316
0 votes
0 answers
44 views

How to set the Exec when bash command is too long?

The desktop file works fine: [Desktop Entry] Type=Action Name=unrar zip or rar file Profiles=unrar [X-Action-Profile unrar] MimeTypes=inode/directory Exec=bash -c "unar /home/test.rar -o /tmp;...
newview's user avatar
  • 205
1 vote
2 answers
674 views

Redirecting stderr to temporary fd in a Bash script

I see that many questions have been asked and answered on SE about redirections in Bash using exec, but none seem to answer my question. What I'm trying to accomplish is redirect all output to stderr ...
mesr's user avatar
  • 407
2 votes
1 answer
69 views

How do I insert my own lib to other binaries in Linux?

My goal is developing a tool for educational purposes which logs commands on a system. Until now have found primitive ways to do this but all these ways can be easily bypassed so I had this idea to ...
Jugert Mucoimaj's user avatar
3 votes
4 answers
2k views

execute a command recursively on the files of a folder in the matching location, not in the original one

I want to recursively convert files from .docx to .doc in a folder. The problem is that all the output files are created in the folder where I run the following command, not in the location of the ...
fich's user avatar
  • 330
1 vote
1 answer
518 views

Is it possible to load up a binary into ram, without executing it?

Like I will use google chrome whenever I use linux (most probably) But I don't want it to auto start when ever I open it. I could open it manually, but I have HDD so it is pain to load for the first ...
Afroz Alam's user avatar
3 votes
1 answer
638 views

Signal handling in shell script with exec and pipe to filter output with grep

I'm deploying a containerized application which outputs an enormous amount of useless messages on startup (the same message for about a million times, without any variation). The message cannot be ...
Namoshek's user avatar
  • 133
1 vote
1 answer
1k views

Need to capture exit code of pylint command using find in Github actions

I am trying to implement a python linter using pylint. But I am getting the score of each python file and also displaying the suggestion to improve the score but I am also looking to terminate the ...
sidharth vijayakumar's user avatar
3 votes
3 answers
2k views

How to print to stdout after exec >/dev/null

In a script, I have a long list of commands that print to stdout. I want to hide all output. So instead of redirecting each command, I put exec >/dev/null at the beginning. What options do I have ...
finefoot's user avatar
  • 3,132
2 votes
0 answers
38 views

Why does the exec redirection disturb / interrupt a pipe to jq? [duplicate]

This is the reduced version of my script: # parse json echo '[{"foo":"bar"}]' | jq # log output to file and stdout exec &> >(tee -a "/tmp/test.log") # parse ...
mgutt's user avatar
  • 487
0 votes
1 answer
446 views

Why basename don't work here [duplicate]

Why when I do this (I know, it's stupid) it returns the full path, not only the filename as expected? ls -l | awk '{print $9}' | xargs -I% find ./my_dir -type f -name "%" -exec echo $(...
Alysko's user avatar
  • 103
0 votes
0 answers
1k views

The total size of the argument list and exported variables exceeds the OS limit of 1MB

I was doing a grid search for some scientific computing project, and got a bunch of log files with parameters embedded in the filenames. $ ls -l | wc -l 38210 $ ls -l | tail -rw-rw-r-- 1 qys ...
nalzok's user avatar
  • 401
0 votes
1 answer
259 views

Working with file descriptors in the (bash) shell?

I came across the following set of shell commands for reading and writing to serial ports, from this thread: stty -speed 19200 < /dev/ttyS0 # sets the speed of the port exec 99<>/dev/ttyS0 (...
First User's user avatar
0 votes
2 answers
176 views

What happens to the file structs of processes after execve

If I understand the man pages correctly, the fd table of a process that forks and execves are copied to the the child process and survive the execve. On the other hand, any other memory mapping is ...
Manouil's user avatar
0 votes
0 answers
143 views

exec terminate command by the space in single quotes

I have a simple bash script goes like #!/bin/bash set -e SPARK_CONF="--master ... \ ... --conf spark.driver.extraJavaOptions='-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps' \ --conf ....&...
Alain ux's user avatar
0 votes
0 answers
28 views

pass output as grep pattern [duplicate]

I wish to pass each line of a file as a grep pattern to be searched in data.txt file. Thus, i need cat allsearchstrings.txt | grep <should be lines of allsearchstrings.txt> data.txt cat ...
Ashar's user avatar
  • 511
0 votes
1 answer
1k views

`exec env` vs `env`

Both exec and env don't fork, see the following example: docker run --rm -it ubuntu:18.04 sh -c 'exec sleep 1 & ps -Ho pid,ppid,cmd' PID PPID CMD 1 0 sh -c exec sleep 1 & ps -Ho ...
Weihang Jian's user avatar
  • 1,257
3 votes
1 answer
547 views

Output to variable or file using (find with -exec and shred)

I have a find command that I exec to shred and it works great; however, I need to capture the output of this and pass to a variable or a file. I have tried so many iterations of the below commands, ...
John Riordan's user avatar
1 vote
2 answers
15k views

How to launch application with rofi using i3wm's exec?

I had this issue and now I know how to solve it. I need to launch applications with i3wm's exec command. ButI use rofi as launchmenu and I have no idea how to make it lauch applications with i3wm's ...
Jan Černý's user avatar
  • 1,441
0 votes
0 answers
966 views

Delete all files in directories tomcat_*/temp on each application restart

We do have an operation script to stop, restart and start tomcat services. I am asked to make changes in the operation script so when starting tomcat with operation_script.sh, All files in directories ...
codehunter-py's user avatar
12 votes
2 answers
4k views

What does `exec 6>&1` or similar do?

I'm migrating some software from Unix to Linux. I have the following script; it is a trigger of a file transfer. What do the exec commands do? Will they work also on Linux? #!/bin/bash flog=/mypath/...
CarLaTeX's user avatar
  • 329
1 vote
0 answers
2k views

How is i3 window manager started by startx in Ubuntu (so that I can configure what display it appears on)?

I want to set up i3 automatically start on a specific one of my three screens (all connected to one Nvidia card). This has proved more difficult than expected. My first choice was to just set that ...
Stonecraft's user avatar
4 votes
1 answer
606 views

How to increment COUNTER in -exec script?

Context: zsh Catalina MacOS: The executable script BatesStamp engages imagemagick to stamp a number to a jpg file: # BatesStamp: OVERWRITES and stamps ONE file with COUNTER (upper left corner) # ...
gatorback's user avatar
  • 1,394
0 votes
2 answers
261 views

exec vscode not redirecting output to /dev/null

I have the following bash script: exec '/mnt/c/Users/WindowsUserName/AppData/Local/Programs/Microsoft VS Code/Code.exe' $@ &>/dev/null & When I run the script I get ➜ ~ ./code foo.js ➜ ~ ...
Kevin Koehler's user avatar
2 votes
1 answer
407 views

How does exec > work in AWS EC2 user data?

I was writing a Terraform module for AWS EC2 that involved executing a bash in the user data section. While I was developing I had an issue in the script I wrote but neither AWS nor Terraform provided ...
Ahmed Khaled's user avatar
1 vote
2 answers
8k views

exec command not found error in Linux

below commands are giving output and exiting the terminal exec sleep 60 exec pwd below commands throws error. please advise on the exec behaviour $ exec test1.sh -bash: exec: test1.sh: not found $ ...
Veera V's user avatar
  • 43

1
2 3 4 5 6