Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [shell-script]

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

0
votes
1answer
4 views

How to cut from one field to a different field in a separate output file?

I am trying to understand cut better and moving cut data to another file. I have a file called numbers with two columns. Each column is separated with one tab. I am trying to swap the columns by ...
-1
votes
2answers
43 views

How to find avg, min, max and all for all file statistics (unix bash shell scripting)

I have a question regarding finding the average, minimum, maximum through shell scripting. Background: I have directories ranging from 1998-2019, there are 1,000 files within these directories. Each ...
1
vote
1answer
71 views

What are the unreadable characters in Linux Anaconda install script?

The Anaconda for Linux installation scripts contain about 750 lines of a pretty straightforward set of bash commands, but they are then followed with 1.4 million lines of characters unreadable (at ...
0
votes
5answers
1k views

Sum all file sizes

I'm new to bash and I need to do a little script to sum all file sizes, excluding subdirectories. My first idea was to keep the columns when you do ls -l. I cannot use grep, du or other advanced ...
4
votes
2answers
119 views

Should the shell read (an script) one character at a time?

While reading an script, the shell will read the script from a file, or from a pipe or possibly, some other source (stdin ?). The input may not be seek able under some corner conditions (no way to ...
0
votes
1answer
112 views

Trying to request a variable before running a curl and read back as integer

echo -e "Enter layoutID: \c" read layoutID echo -e "Enter playlistID: \c" read playlistID echo -e "Enter siteID: \c" read siteID curl -H "Content-Type: application/json" -d '{"LayoutId":$LayoutId........
1
vote
0answers
369 views

Can't get polybar to display certain modules, when using xrandr --same-as function

I am using the folowing script. #!/usr/bin/env sh # Launch polybar (depending on multiple monitors or not) if type "xrandr"; then for m in $(xrandr --query | grep " connected" | cut -d" " -f1);...
-1
votes
1answer
4k views

how to install firefox.tar.bz2 on kali linux [closed]

I have downloaded the firefox.tar.gz2 file and archieved it. How to get it running? I am running Kali Linux.
2
votes
2answers
163 views

How to execute Command which is in a variable

My Condition is like below. SEARCH="find `pwd` -name" bash> $SEARCH resources.xml | grep $SEARCH_DIR | grep $1 | grep ‘cells’ But am not getting the pwd as referenced in that variable.
3
votes
2answers
3k views

how to add line in a /etc/sudoers file with using shell script (50servers)?

I want to know script which can edit /etc/sudoers file and let me add {{{{{userid ALL=(root) ALL}}}} to 50 server I have on same network?
3
votes
2answers
59 views

Iterating fieldA in CSV file, where fieldB has specified value

I've been trying to setup a script to run on gitbash, to process a CSV file so each record that has a specific value, the last field is changed from empty ("") to a value that iterates from 1 to 16. ...
0
votes
1answer
340 views

Help creating for loop to zip files with particular suffix and extension

I'm trying to write a script to zip particular files with specific suffixes and different file types in a directory. I see posts about zipping all files of particular extensions, but am hung up about ...
-1
votes
1answer
134 views

Writing a Bash script pulling every word separated by a comma out of a text file

I'm trying to write a Bash script that will read a text file and pull out every word that is followed by a comma on a new line. I tried using grep but it prints the whole line that has a comma in it, ...
0
votes
1answer
310 views

Checking the execution of the previous command

I have to perform an operation in a script by connecting to oracle database.I am trying to use expdp command in my shell script to dump the data . Vi ban.sh expdp hr/oracle@oracle table=man ...
0
votes
3answers
139 views

Formatting output from awk command in script

If I run this command: awk -F'[="]+' '/^(NAME|VERSION)=/{printf("%-17s: %s\n",$1,$2)}' /etc/os-release from a terminal, I can retrieve this: NAME : Debian GNU/Linux VERSION : 8 ...
0
votes
1answer
407 views

Bash- modify code for a custom output statement

The script will read the contents of a user-input file and count the number of employees with a specific job. Ex file line: Sophia Lewis, 542467, Accountant The script I have so far is: if [ -s $1 ...
1
vote
2answers
74 views

Script to Process txt file to CSV

I am trying/attempting to write a script to turn this: Mikrotik01#show unique routing entry | 192.168.255.232 | inc ID Thu June 10 15:21:32.808 CST Unique Entry: 192.168.255.21 Unique Entry: ...
2
votes
1answer
1k views

Creating shell script to print weekday and weekend

How to create a simple program using for loop and if. my code: for i in mon tue wed thurs fri sat do echo weekday: $i if [ $i == thurs ] then echo weekend: $i+1 fi done and ...
0
votes
3answers
159 views

Scripting - if grep “Used : X GB” > Y then

I have scoured the internet for a way to query an ESXi hosts used RAM, and I found one which even included the Used Mhz to boot, in a nice output. My real end goal is to get an XYMon script to monitor ...
-3
votes
1answer
37 views

Help required in logic

I have a below requirement. I am validating one of my code-file using one utility in shell script and writing that Error,Warning messages to an output file. Now i need to write a logic like if i ...
0
votes
0answers
77 views

RHEL Anaconda kickstart installer error message on terminal console with log and exit immediately

My kickstart script is like this: %pre --log=/tmp/log wget --no-check-certificate http://192.168.2.33/file [ $? -eq 0 -a -f file ] && tar --ignore-failed-read -xzvf file .... %end wget ...
14
votes
1answer
14k views

Use md5sum to verify file in a script

I want to verify a file using md5sum -c file.md5. I can do that by hand, but I don't know how to check the validity in a script.
3
votes
1answer
164 views

tcpdump with multiple subtypes specified?

I'm trying to create a bash script to detect deauthentication attacks (I am on Mac). Whilst I am aware that the command: $ tcpdump -l -I -i en0 -e -s 256 type mgt subtype deauth will detect ...
1
vote
3answers
60 views

Using file content as arguments multiple times

I have one text file with names of a bunch of .txt files (not full path names) that exist in a directory. Each of the files, have a (full) path to another file which I would like to delete. Suppose I ...
23
votes
8answers
99k views

Add lines to the beginning and end of the huge file

I have the scenario where lines to be added on begining and end of the huge files. I have tried as shown below. for the first line: sed -i '1i\'"$FirstLine" $Filename for the last line: sed -i '...
-2
votes
3answers
92 views

How to make commands like : sudo or read

I am trying to make a sudo-like/read-like command (To just see what happens, also for roleplay) so I made my bin directory (Because I am using Linux on a Chromebook) then I made a atc folder (that is ...
0
votes
1answer
13 views

Open a tmux session and then change to different user without password prompt

I am trying to create a script that opens a new tmux session and then runs a command inside that tmux session as a different user. The purpose of this is to create a new tmux session for a game ...
0
votes
0answers
832 views

Bash Script - How can I concatenate several strings containing special characters? [on hold]

This is a simplified version of a script I'm working on. I'm reading numbers, which contain line breaks, from a file. I need to concatenate each number with other strings, and I need to pass that ...
0
votes
1answer
21 views

Reading an argument and creating a tempfile from it to use within the script

I am trying to write a script that would count the number of columns in a file. However, I don't know what the name of the file will be. I am trying to create a file called tempfile which has the ...
2
votes
1answer
19 views

Replace part of a vdf file

Again I am attempting to alter configuration file via script. I looked into jq but jq seems to support the .json format alone. .vdf is almost exactly like .json except that there are no commas. ...
-1
votes
3answers
83 views

How to make a password in script [on hold]

I am working on a terminal-based program and thinking there should be a password (That I would specify if I upload or make the user create one, I have tried #!/bin/bash PS3='Are you sure you want ...
0
votes
4answers
118 views

How do I get systemd to correctly manage a script with background processes?

I have a shell script which runs three programs in the background, a few in the foreground and then trap and wait, and I have set up a unit file so systemd can start it and restart it if it fails. I'...
0
votes
1answer
2k views

Find if the file is compressed or not

I need to find whether the file is compressed or not in script.If it is compressed I need to uncompress and send as attachement. My find command results in two files sum12.pdf.Z and sum23.pdf.Z My ...
1
vote
1answer
40 views

Confused about determining if a shell script is running interactively

I only want to determine from my POSIX shell script, if it is running interactively, but for some reason, the following function: running_interactively() { printf '%s' ${-} | grep -F i > /dev/...
0
votes
0answers
13 views

On Ubuntu Server latest LTS on Digital Ocean how can I automatically detect github commits? [on hold]

I have a git repo on windows, say I am coding an html page, index.html or whatever. I save this in my git repo locally on windows, then I commit to at github.com/myusername/myrepo to say the master ...
0
votes
1answer
29 views

sed command working only when no outfile is written

I'd like to change this file eq.txt 2018-05-03T18:46:05.050Z 11.8314 44.0586 10 4.3 USGS 2018-05-01T05:16:59.270Z 11.0366 43.2334 10 4.1 USGS 2018-04-26T11:13:20.590Z -5.4109 36.5557 10 4 USGS 2018-...
0
votes
2answers
56 views

Grep in file with whole cat output

I search/try to write short script (for if loop) to do grep in file by whole cat output. Already I tried #!/bin/bash find -name 'xmlrpc.php' -execdir bash -c ' if [ -e ".htaccess" ] ; then if grep -...
0
votes
1answer
27 views

How to input a digit into files created from a loop?

This is the original problem: Create a script fivedirs that does these tasks: make a directory five make five subdirectories five/dir1 through five/dir5 in each subdirectory, make four files, ...
-1
votes
1answer
21 views

How to append * to the String and assigning a prepared SQL Query to another variable? i.e., (select * from …)

I'm trying to create a SQL Query and trying to assign it to some variable but I couldn't do that. TABLENAME=foo QUERY="select * from $TABLENAME" echo $QUERY I'm expecting the Query would be select * ...
-1
votes
0answers
30 views

How to do operation math with number words shell script?

I want to read a file and inside the file have number words. I have to do operation math. but I dont know why my script doesn't work. Exemple : seven one minus six one the answer in the terminal : ...
-3
votes
1answer
36 views

Script program for checking IP connectivity [on hold]

I need a program to check the IP connectivity. Like I will be having more than 100 different IP addresses. For each IP address, I need to check whether it has connectivity or not. My challenge is I ...
1
vote
1answer
2k views

lftp return code

I have written below code to get listing from a remote server. echo "set xfer:log yes" > batchfile.txt echo "set xfer:log-file Templogfile1.txt">> batchfile.txt echo "open -p $rport -u $...
0
votes
0answers
22 views

sed Shell Script not working correctly

I have this shell script that is supposed to go through a file and replace its primitive types with other specific text (it's for an assignment). The script is below: #!/bin/bash #Goes through an ...
1
vote
1answer
21 views

Starting wpa_supplicant via script in systemd not working properly

I've written a script to manually start the wpa_supplicant function on a Fedora/Centos7 machine with a wireless NIC. Due to static routing issues, I cannot use NetworkManager (nor do I want do with ...
1
vote
2answers
297 views

Overcoming newlines with grep -o

I have a file similar to such. SampleOutput { "1": { "state": "RUNNING", "stats": { "name": "some-file", "uris": [ "some-example.com" ], ...
2
votes
3answers
10k views

Null message body; hope that's ok

I have the following command below as part of a cronjob. When I run the command via cron or at the command line, I get Null message body; hope that's ok. The contents of the email are empty but when ...
0
votes
1answer
24 views

compare a certain number of lines between columns of two files

I have a thousand files and I need to verify if they all have exactly the same information in the second column up to a certain number of lines. Below an example. I would like to print the names of ...
1
vote
1answer
20 views

Commands Not Found when Passed through SSH

System: Red Hat Enterprise Linux Server release 7.6 (Maipo), 3.10.0-957.el7.x86_64 GOAL: Collect configurations for data from multiple servers to validate they are the same. What Works: ssh $...
1
vote
1answer
18 views

korn shell - if a variable exists in an array stop processing without exiting

How would one evaluate priority of items in an array such that you only process the highest priority item that exists? Let me try to explain, if I had an array set -A array low medium none high ...
0
votes
3answers
291 views

Find a word before find another

I want to find the table that contains one value. I see some solutions using mysql, but I started to think, how can I do this in linux?, and I don't have any Idea, but I want to know. So, the steps ...