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
1
vote
1answer
22 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 but ...
0
votes
2answers
52 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 ...
0
votes
0answers
26 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 ...
11
votes
2answers
934 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/...
0
votes
0answers
75 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 ...
4
votes
1answer
116 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) # ...
0
votes
2answers
43 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 ➜ ~ ...
0
votes
0answers
40 views

Interrupting rsync crashes a container

Consider the following script (/tmp/a.sh). It prepares an environment to run rsync: #!/bin/sh -eu docker run --rm -it \ -v /:/host \ alpine sh -c ' apk add rsync shadow procps ...
2
votes
1answer
168 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 ...
0
votes
2answers
415 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 $ ...
0
votes
3answers
86 views

How to pass grep result to a varible so i can use it with exec tar command?

I am trying to compress all folder in dir based on some regex so I used grep to filter out the output now i need to use tar and folder name. For example I want to .tar.gz each top level directory to ...
0
votes
1answer
79 views

php exec/shell_exec behavior CLI vs CGI

I am trying to use php to run some system commands and am getting a behaviour that I don't fully understand. If the php script is run from the command line I get the results I expect. But running it ...
0
votes
0answers
43 views

Exec Not Updating Values from Certain Bash Functions and Variables When Prepending Script Output

I am logging messages in Bash where I add some useful information to the log message to help provide context. However, in the final output most of my variables and functions appear to only use their ...
-1
votes
1answer
145 views

Output of this command Linux [closed]

Please do anyone has an idea about the output of this command , I have googled a lot about it but I can't find anything useful find . -type f -exec grep -H PATH {} \; Thanks in advance
0
votes
0answers
21 views

Commands where Export is Required to Persist Variables in Subshells

After reviewing this SO answer, my question is: Besides $ ./your_script $ ( exec /path/to/shell/bin -c 'some command(s)' ) $ exec /path/to/shell/bin -c 'some command(s)' are there any POSIX built-ins ...
0
votes
0answers
38 views

OpenBSD 6.9 - ENOMEM error on execve (execvp)

I've compiled a program on OpenBSD 6.9 and when I execute the program, I get an enomem error related specifically to execvp which the man pages say is a font-end for execve. The execve man page ...
0
votes
1answer
45 views

process hangs after redirecting stderr using exec

I want to redirect stdout and stderr to 2 pipes one for each to create the pipes I used: mkfifo -m 0666 /var/run/log_stdout.pipe mkfifo -m 0666 /var/run/log_stderr.pipe and it works fine, but ...
0
votes
1answer
104 views

ip netns exec cannot start ONLY mate-terminal and gnome-terminal?

I am using the newns script from here: https://superuser.com/questions/983727/route-only-specific-traffic-through-vpn ... except on this system: $ mate-about -v MATE Desktop Environment 1.24.0 $ cat /...
7
votes
2answers
862 views

Why does exec print its output after the program exits?

I'm writing a program to pipe one command to another. Inputs will be from the command line: $ ./a.out ls '|' wc c2 PID 6804 c1 PID 6803 PARENT PID 6802 $ 2 2 17 Why does the output ...
0
votes
0answers
69 views

Image converstion to webp format using graphicsmagick

I am trying to convert all jpg images into webp format in my folder. I use this code : find /var/www/uploads -iname '*.jpg' -exec gm convert -format webp {} + It does not work. Anybody has ...
0
votes
2answers
34 views

How to delete ALL directories but NOT files from another location in execv? [closed]

Let's say I'm at the home directory and I have a directory called 'Apple' that has 2 directories (let's say I don't know their names) with contents in them and several files. I open my terminal in ...
0
votes
1answer
214 views

Why is 'ls' being created by execve() call and not fork()

From my understanding whenever you type a command such as 'ls' in your shell, the parent process which is my shell duplicates itself using fork() system call and then uses the exec() system call to ...
2
votes
1answer
154 views

How can I redirect all output of a script to a file and replace passwords?

I'm running a ksh script on AIX 7.2. In debug mode I want to redirect all the script does to a brkpt-file. The script also makes logins to another application and therefore uses a password (let's say &...
0
votes
1answer
227 views

Execute an shell script with sudo inside from php

I want to execute a command line command as root from a php file. In my case I want to view the crontab file in my php page. Running the sudo command in php is not recommended and on my raspberry pi ...
0
votes
1answer
129 views

What does `exec` with no arguments do?

exec with no arguments returns success and apparently does nothing. Why?
3
votes
2answers
111 views

Count lines in csv files nested in subdir using find exec

I'd like to run two piped commands on the results of find on some nested csv files, but I miserably fail. Here is the idea: $ find ./tmp/*/ -name '*.csv' -exec tail -n +2 {} | wc -l \; in order not ...
0
votes
1answer
72 views

find & copy command is not copying same number of files

I'm trying to use find & copy on some files but the problem is if i only run find command and check wc it shows some result, after copying these files to some other directories it shows some other ...
0
votes
0answers
44 views

Writing output of ls using exec to a variable [duplicate]

I am trying to write the output of exec ls to a variable. I am new to bash so probably overlooking something simple. The aim is to check a mount within a docker container and if it comes back with a ...
6
votes
3answers
2k views

Find -exec dry run?

Is there a way to see what the result of a find . -exec somecommand {} \; would be with substitutions, without actually running the commands? Like a dry run (or test run or print)? For example, ...
-2
votes
1answer
262 views

Does execve() make a child unrelated to its parent?

When a process fork() a child, the two processes are related. The child inherits a lot of things from the parent, including some IPC objects such as pipes and anonymous memory mappings. If the child ...
2
votes
1answer
106 views

Why does `exec init` work in podman but not buildah with the same options?

How are these two commands different? Both of them launch a shell as pid 1 and make the same mounts and volumes, buildah run --tty --mount type=tmpfs,destination=/run -v /sys/fs/cgroup:/sys/fs/cgroup:...
1
vote
1answer
69 views

Issues with bash script containing exigrep command when invoked from PHP webpage

I have a bash script to extract information from exim_mainlog. When the bash script is run from a putty command line (logged in as root), the extracted data is properly written to an output file. ...
2
votes
1answer
343 views

Hot replacing a PID 1 process inside a container without crashing

As you know a OCI container (more commonly known as Docker container) terminates once its entrypoint process (a.k.a. PID1 inside the container's namespace) exits. However, I'm curious if there's a way ...
1
vote
1answer
270 views

FIFO-based semaphore explanation

I am trying to work on some parallelization of many processes (task send/to be executed on many (let's say hundreds) nodes). I came across this solution: https://unix.stackexchange.com/a/216475 # ...
-3
votes
1answer
51 views

Basic command problems

I tried to figure out what is the difference those commands (for a school project), but for me its chrashed or running for more than 10min~ So, the sample: sudo find / -type f -exec file ’{}’ ; | ...
1
vote
2answers
52 views

How to recursively shift `<user_id>`:`<group_id>` by a specific value using `xargs` or `exec`

I'm trying to recursively shift <user_id>:<group_id> by a specific value using xargs or exec. I'm having difficulty with passing output from find to variable with stat function. I'm ...
-2
votes
1answer
587 views

Exec format error

I know this gets thrown around a lot, but it just didn't make sense to me. So, I compiled C code using the installed gcc compiler but it just would execute. Many other posts said that it was probably ...
1
vote
1answer
123 views

script hangs due to `exec` on AiX servers with ksh shell

Below script runs fine on all Servers in my infrastructure. However, I recently discovered that it fails to complete execution and simply hangs on Aix servers with ksh shell. cat myscript.sh export ...
0
votes
1answer
230 views

Trouble with the command "-exec ls -l {} "

I was working on a lab and was having trouble with the function of part of a command we are supposed to learn. Here it is: find . -name "*.txt" -exec ls -l {} \; I have determined that the ...
0
votes
1answer
100 views

How did Linux load this exe compiled with C#? [duplicate]

I just discovered something really surprising. I can compile a simple C# hello world on my windows computer using csc (from Visual Studio), copy the resulting exe file to my Linux computer, and ...
1
vote
0answers
46 views

Prompt is not shown after running a script with an "exec" command redirecting stdout and stderr [duplicate]

An example script is shown below. The meaning of the syntax - exec > >(tee -a "$file" "$sec_file") 2>&1 , is to print to the console the stdout and sdterr , and also ...
1
vote
2answers
87 views

perl cannot `exec` to binary

In my fresh installation of Debin, perl intepreter is installed by default (in other words, I have no other perl packages yet). However, trying this: $ls a.cpp b.cpp $ perl -e 'system "g++ -o a....
2
votes
1answer
1k views

Identical execve causes "Permission denied" for one program but not another

Permission denied shows up when I try to open some attachment in Thunderbird. Yet, it doesn't look as a Thunderbird bug, because when I strace the process I see it issues the correct call. Yet it ...
1
vote
2answers
370 views

Output tee to stdout while writing to a FD using here-strings

I am trying to output tee while writing to a custom file descriptor. Example: exec 4>"/tmp/testfile.txt"; # open FD 4 tee -a >&4 <<< "Output this to stdout" # ...
3
votes
3answers
137 views

Move files that have a value above a threshold in any row of a specific column

I have a large number of files in a particular folder. I would like to move these files to a subfolder ONLY IF they have at least 1 value above 0.5 in any row of column 4. In a separate command I'd ...
0
votes
0answers
56 views

Mount does not work in script when run by php

So I have a script that's placed in my apache2 html folder and should be executed by an http post. The script requires root (I know that's not safe at all, ignore that please), so I set the user www-...
0
votes
1answer
259 views

exec command won't accept xargs, hangs on command input

I'm not super familiar with exec. I was running through some tests and examples. I wanted to pass a command written in a file to it. I'm expecting that command to be run with exec just as if it were ...
3
votes
1answer
394 views

What is this script doing?

#!/bin/bash echo 123456789 > out.txt exec 3<> out.txt read -n 4 <&3 echo -n 5 >&3 exec 3>&- Was asked the content of out.txt at the end of script, in an interview ...
0
votes
1answer
82 views

Where is do_execve located?

In Linux, there is a function called do_execve in fs/exec.c. Where is the object file of the function located after Linux has been compiled? Where is the .ko file that contains it?
1
vote
1answer
41 views

Persist file redirection between exec calls

Is there a way to persist file redirection commands between exec calls? For example, there are two bash scripts. In script 1, I am setting up redirection of stdout and stderr to file. Then exec-ing ...

1
2 3 4 5 6