Questions tagged [shell-script]

Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

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

Oldest process of users in who

How to show the oldest process of each user listed in the command who? I've tried using the command ps -u $user --sort +start_time but couldn't find a way to filter the users and extract the PID from ...
0
votes
1answer
28 views

Remove all rows in a CSV file without corresponding/matching timestamp in another CSV file

I have 2 CSV files which look like follows: file1.csv col1,col2,col3,col4,date,time,col7 1,2,3,4,2019-07-20,12:40:00,0 1,2,3,4,2019-07-20,12:43:00,0 1,2,3,4,2019-07-20,12:44:00,0 1,2,3,4,2019-07-20,12:...
1
vote
1answer
34 views

command not found when script run inside another process

This is running in qBittorrent, as a completion script. When the download is complete, I want this script to run and ship off all the files to a remote server. The script, when run from terminal ...
4
votes
1answer
22 views

What is POSIX way to handle SIGINT (Ctrl+C) in subshell so that the surrounding shell will not be interupted?

The following script outputs "12" (preceded by "^C" in shell), if Ctrl+C is pressed #!/bin/bash ( trap 'trap "" INT' INT; sleep infinity; printf 1 ) printf 2 but if I ...
0
votes
1answer
30 views

Difference ways to acces a variable in shell script

I am a beginner in Unix commands as I am currently studying how to write scripts. However, I can't understand how to actually access a variable. Suppose I have a variable called name ($name), I see ...
0
votes
2answers
39 views

How to pass a block of text to python from bash

I have a block of text that I want to cat into bash and then send to python so I can work with it more. So my command line is cat input_file | sh bash_file.sh My sh file is #!/bin/sh input_data=$(cat) ...
1
vote
1answer
42 views

Map field of first file based on patten matching in second file

I have two tab-delimited files where I need to match text in the first column of file 1 to any position in lines of file 2. Upon a match I then want to print what's in the second column of the ...
0
votes
2answers
25 views

Using a dynamic array name to retrieve value

I'm trying to retrieve a value in a for loop but have failed with every effort. In this script, I have to declare the remote path for my SSHFS mount script. In the code below, I'm storing the path ...
0
votes
1answer
36 views

How to move all files in dir to another, but copy latest?

I'm trying to write a backup script that moves all files from a directory, but only copies the latest modified/newest file. I'm running into some trouble where I'm not able to return the correct ...
1
vote
1answer
33 views

Autodelete generated files after shell script exits or crashes

I have a pretty long bash process that generate a few temporary files, some of them, with generated and almost random names. I will like to avoid to manually delete them after a process failure. Is ...
-2
votes
1answer
70 views

Move files if recieved with .done file

I have a system with a watch folder where people/companies can upload new files via FTP. In this watch folder they should always upload 2 files: One binary file with a prefix name of ABC* and always ...
0
votes
2answers
41 views

How to define and set a variable from a file?

I have two files one.txt and other two.txt. one.txt file contents: "21" "22" "23" two.txt file contents: "Hi how are you" "Hello who are you" "...
-1
votes
0answers
26 views

How can I recursively check an entire file system for IP addresses?

I've found How to check if any IP address is present in a file using shell scripting? but I don't know how to apply that to the entire file system.
-2
votes
0answers
35 views

Bash script that will automatically create a new user and add the user to a group

Script will then check whether the username exists and if it already exists, then the program will prompt for a new username. The script must check whether the group exists or not, if not it will ...
1
vote
1answer
35 views

How to continue running the script when a script called in the first script exited with an error code?

I am trying to write a bash script that will run a second script repeatedly until it fails and capture the stdout and stderr of that second script. I have managed to deal with most problems ...
-3
votes
1answer
50 views

How to print out $0(script name) in front of the exit-status?

Hei, I need help with how to print script name infront of exit status. For instance my script name is myprog.sh and in it I have written exit 123. So when I run the script and then type command echo $...
0
votes
0answers
18 views

Exit Reverse Shell gained while pentesting through shell automation

I am trying to automate a task in pentesting using bash script,and while running the script i am sucessfully gaining the reverse shell but unable to run any commands in the reverse shell gained. ...
-1
votes
2answers
108 views

Manage a big file thanks to text-processing with AWK or a script

To answer to @Ed Morton, Inputs ... useless_words Number_100 : Message xx Dublin xx Paris useless_words -Code 452 useless_words useless_words Number_100 : Rename message (old 452 ; new 557) ...
0
votes
0answers
36 views

Systemd service not read usb before shutdown

I have a small script that copy some files from linux OS to usb when the machine shutdown. My goal is I want the systemd service stop shutdown process then run script and then shutdown the machine. ...
0
votes
2answers
30 views

Is there a way to interact with a shell but from an app or separate program?

I am trying to find a way to both receive the output of a shell and then return output, but from a different front end interface? I am trying to incorporate the Linux terminal into a potential ...
1
vote
2answers
93 views

Editing a file based on a pattern appearance

I have a file that contains text and numbers like this: state(1, s(1,a), [s(1,b)]). state(1, s(1,b), [s(1,a)]). state(1, s(2,a), [s(2,b)]). state(1, s(2,b), [s(2,a)]). state(1, s(3,a), [s(3,b)]). ...
2
votes
1answer
43 views

Can we read the variable name as a parameter value through the Bash command line execution?

We have a simple script where we execute the script using the command: script.sh 123 456 Script content FirstNum=$1 SecondNum=$2 Instead of using $1 and $2 inside the script, can we pass the command ...
0
votes
0answers
20 views

Unable to run retropie and detatch screen on Debian 10

I'm trying to run a script that launches retropie and pushes the output (the game) to the remote display. I've gotten this to work perfectly on PI3 b+ running the Raspi OS, but I can't seem to get it ...
0
votes
0answers
27 views

Why source same script twice is exiting the shell?

I have written a bash script to create a git worktree- cr_wt #!/bin/bash unset CDET_ID unset WT_DIR source ~/.bashrc usage() { echo "Usage: $0 [ -c CDET_ID ] [ -d Directory Name ]" ...
1
vote
2answers
34 views

test standard output with fish

I have a script that prints a string to terminal, and I want to check value of myScript output.(in this case resultString) I tried with this method, but it didn't worked. (for simplicty i replaced my ...
0
votes
1answer
36 views

Bash Script for ExpressVPN

I am currently struggling to run a custom expressVPN script that will run several commands one after the other when I click on the launcher (that links to the script) I have so far managed to get ...
0
votes
1answer
39 views

A graded print of asterisks

im a beginner, And i want to writing a script ('for' loop) - Requests a number Multiply the number by 2 and start a raw of asterisks And presents as here: (for example the number is 4) ******** ****...
0
votes
0answers
6 views

FTP and mget problem in shell script

Is it plausible that mget command may not be able to retrieve a large file 100mb, 1gb, due to it still being written by the host? Is there a method to check? I would need to check FTP status codes, ...
0
votes
0answers
42 views

Files come back from deletion

I have an script that does this: rm -rf "$test_dir" && sync && mkdir -p "$test_dir" unzip -qq "$zip" -d "$test_dir" # compile and run some ...
1
vote
1answer
28 views

Can move but cannot remove from shell script

I am glad I found this workaround, but maybe someone can explain this to me. I became so frustrated with it that I even explicitly spelled out the pathname each time. I cannot remove files with a ...
0
votes
2answers
20 views

Create the same subfolders in another folder with copying files with certain names

I have a directory which has many sub-folders and under sub-folders there are other sub-folders. I want to copy all the directory and subdirectories into another location with copying only files with ...
0
votes
1answer
35 views

How to put piped input into a variable

I'm new to bash so this should be pretty basic but I can't find it so far. I am going to have an input cat input_file | sh_file.sh output_file I want to get the information from the input_file so ...
0
votes
1answer
28 views

Script using data/input which contains variable names [duplicate]

So I have a file "Directories.dat" that contains a list of directories for a script to read that runs on multiple machines. Due to this, the list of directories in the file is often defined ...
0
votes
1answer
61 views

Storing find results in variable then passing to cp?

I have a need where I must work with a set of files based on time elapsed (as I do not have control over when new files are added to the remote directory). I must do several operations with this set ...
1
vote
4answers
71 views

What's the difference between if ! [[ foo ]] and if [[ ! foo ]] in Bash?

I understand that ! is used to negate an if condition in Bash, but I've just seen code which takes the format: if ! [[ CONDITION ]]; then SOMETHING fi Is there a difference between this format ...
0
votes
1answer
44 views

shell variable with multiple values

this probably is very easy to do but I just can't get my head around it I've got a script that grep some values from a file (file1) sort of var1=$(cat file1 | grep foo | grep bar) if I echoed $var1 ...
0
votes
0answers
19 views

write output files for jobs submitting via Torque qsub

I am working on a HPC where I have to submit jobs via TORQUE. I was able to create output file for the following but unable to do the same when going through job queue. I was able to write hello.txt ...
0
votes
1answer
31 views

Script to get a list of local IPs and look for an IP

I would like a script to look for an IP address among others. I use the following command to generate the list: ip -4 neighbor show But I don't know how to look. command | awk ... or for i in ...
0
votes
0answers
9 views

Checking if specified jar is running .. if it is running then sending mail from linux machine

I have some jar services running in my machine .. i ran below command there ps aux| grep java this command gave me results .. but now what i want is if any of jar is not running then it should send ...
0
votes
1answer
30 views

Can't run zsh script that's in path

I've been trying to run a simple script named 'post-install.sh': #!/bin/zsh sudo apt-get update -y This script is in ~/bin. Relevant commands: % echo $PATH /home/$USER/bin:/usr/local/bin:/home/$USER/...
0
votes
0answers
29 views

Find Command Example - OEL7

find /path -type f -name '*' -not -name "data*" -mtime +1 -delete I want to ask about this command. As I understand, this command go to path and delete according sysdate-1 all of the files ...
1
vote
1answer
22 views

Issue in changing directory while doing ssh

I have the following scenario, I have script that runs bash script on another remote machine The command to ssh is ssh knode@192.18.48.0 'bash -s' < test.sh test.sh #/bin/sh bash ./trigger.sh ...
0
votes
1answer
39 views

Source file corrupted when the rsync was interrupted

I am running a script to rsync a folder from client to server. Syntax applied on the script is rsync -avzP --append-verify --delete -e "SSH parameters" source_dir user@host:destination But ...
0
votes
0answers
11 views

Using network namespaces in production?

I have been looking at two pages https://gist.github.com/dpino/6743226422594b6c02c7150b6e5e7df7 (no nat) and https://gist.github.com/dpino/76b0bf7f522bd0d2e442eca06ae9db76 (nat but I don't know what ...
0
votes
0answers
25 views

Having trouble finding best way to redirect hosts that are currently down in ping script I wrote

Good Morning - I wrote a bash script to read several files and to ping the host to see if it's available, if it's down then send an email. This will be ran in cron. The part i'm stuck on is when i'm ...
0
votes
1answer
32 views

How to escape reserved character on command line or shell script in linux?

It is known that the character (!) Is reserved, the curious thing is that it works on the common user, but does not work as root, I tried some approaches to solve my problem, but without success, I ...
-2
votes
2answers
54 views

How to do styling for HEADERS in HTML table [closed]

My file contain below comma separated data , where first row is the header File data : Name,Rollno,Course,Language,Subject,Awarded Vilas,1,MBA,Account,MB,1 Ajay,2,MMM,Subject Matter,SU,2 Fedrick,33,...
1
vote
1answer
26 views

How to set an environmental variable from another script?

I set a variable WORKSPACE="$(git rev-parse --show-toplevel)" in ~/.bashrc - which essentially sets $WORKSPACE to the root of the git repository so that I can write alias for some of the ...
2
votes
2answers
98 views

How to create count down timer

I need to display decreasing order count down timer from 20 sec till 00 sec If he/she fail to enter password within the given 20 sec then exit with message your time is over Output : you have 20 sec ...
-4
votes
2answers
79 views

replace every second value in a sequence with special character '*'

Let's take Input from user as 9. So the Fibonacci series upto 9 is as follow's 0,1,1,2,3,5,8,13,21 Expected Output : 0,*,1,*,3,*,8,*,21 Below is the following code which i work around to implement ...

1
2 3 4 5
272