Stack Exchange Network

Stack Exchange network consists of 174 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
5 views

When does the loop starting with while [ -n “$1” ]; executes?

I have a shell script with while loop starting with while [ -n "$1" ]; do I know that $1 refers to the argument right after the name of the script, ie firstargument, when I execute ./myscript.sh ...
4
votes
1answer
41 views

diff showing only differences inside line

I want to compare lines in two files, but to minimize noise in the output, I want only the actual differences in the lines to be printed. For instance, given the two files below: a.txt a b c d e f ...
0
votes
0answers
16 views

Menus and Return commands in Shell; Stuck in a loop

I have a menu that uses the case command to switch to a sub-menu that then calls to a shell script (.functions) as follows: . .functions loop=z while [ "$loop" = z ] do clear tput cup 3 12; echo "...
0
votes
1answer
38 views

what does >& mean in a shell command?

I actually have 2 questions: What does >& mean in a shell script as in /usr/bin/x_app >& /tmp/blog.txt? Shouldn't a number follows & to make it a stdout/err thing? As far as I know ...
-6
votes
0answers
20 views

Need a shell Script in Linux to telnet all ports and get the status of each port [on hold]

Need a shell script in Linux to telnet all ports and get the status of each port. I have to check for about 300+ IP's
2
votes
2answers
60 views

import environment variables in a bash script

I set some environment variables in a terminal, and then run my script. How can I pull in the variables in the script? I need to know their values. Simply referring to them as $MY_VAR1 doesn't work; ...
4
votes
2answers
280 views

The files with the extension bash and sh

I made some researches about the files with bash and sh extensions. Most of the people and resources say that if a file has bash extension, then it contains bash scripts. Likewise, the file with sh ...
0
votes
1answer
32 views

ForLoop on tar files

I am trying to write a script that checks for the disk space and then act based on the used percentage of the disk. In the event that the threshold is exceeded, I want to be able to delete some files ...
0
votes
2answers
72 views

how to check OS is linux or other?

we need to check if the following remote ip's are linux OS or other as win example 12.43.223.4 23.54.67.3 23.5.6.3 we have Linux machine - redhat , and from this machine we need to identify the ...
0
votes
2answers
25 views

Occurence Count

184.13.80.102 - - [07/Jan/2019:00:33:10 -0500] "GET /?p=454 HTTP/1.1" 200 8822 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0" 184.13.80.102 - - [07/Jan/2019:20:16:...
0
votes
1answer
21 views

Maintaining several constants for several bash scripts

I have several individual bash scripts. They do different things, and are large (70-100 lines each). Thus I have kept them in separate files. But they are all related to a central problem and hence ...
1
vote
1answer
34 views

Generating a report from bash output

I am currently trying to write a script in Bash that can run a set of unit/integration tests. I have that part working, but what I need now is to be able to output a summary at the end. I have been ...
-1
votes
4answers
54 views

SQL operation on csv file using bash or shell

This is my input file 0164318,001449,001452,001922 0164318,001456,001457,001922 0842179,002115,002118,001485 0846354,001512,001513,001590 0841422,001221,001224,001860 0841422,001227,...
-1
votes
3answers
49 views

How to put a comma between two columns in a text file

This is my text file: 0019121002313002316003135 0057936000814000814003023 0081638001519001523001176 0090531001841001842002633 0111210001515001518000912 0115400001807001828001593 I want the ...
1
vote
2answers
24 views

Shell script-How to return maximum value in array?

I have a array: ARRAY=(12.5 6.2) I wish to return the maximum value in ARRAY which Output is 12.5 Anyone can share me ideas? I have try this: max=0 for v in ${ARRAY[@]}; do if (( $v > $max ...
0
votes
1answer
32 views

Bash script to move through folders, unzip, and move files up one directory

I have a group of folders that all have zip files in them that may contain 1 or 2 files in them each in a new folder. (see diagram below) I want to point the script at the top level directory and ...
2
votes
1answer
50 views

Cleanup Script for macOS

I have a bunch of shared Mac workstations with dozens of users. These users constantly leave large files on their desktop and in the trash, which eventually fills up the local hard drive. I want to ...
0
votes
1answer
28 views

Renaming Multiple files in different directories [duplicate]

I have about 5TB of data stored on Synology NAS servers with a DSM of 6.1+, so bash should be available for use on these systems. The issue is that we are currently archiving this data to external ...
0
votes
0answers
20 views

Avoiding echo -e [duplicate]

I would like to store an HTTP request in a variable and then use it with OpenSSL I now have HTTP_REQUEST="HEAD / HTTP/1.1\\nHost: ${HOST_HEADER}\\nUser-Agent: check_ssl_cert/${VERSION}\\nConnection: ...
0
votes
2answers
47 views

Extract and rearrange from file

I have file which I want to extract and rearrange certain data , Old file contains a raw data this file is Input reference:cve,2017-8962 sid:45885 reference:cve,2016-10033 reference:cve,2016-10034 ...
0
votes
3answers
30 views

Using xargs command

Can i use ls - t | xargs > output.txt by being outside the directory for example I want to access /home/123/script/final directory and then perform the above function. Something like this: ls - ...
-1
votes
0answers
27 views

How to capture a terminal command and replace by another one?

I want to redirect the user's command line, to copy another folder when they tried to git clone content from a specific folder. For example: git clone https://github.com/delivery.git john_copy I ...
-1
votes
0answers
26 views

A script that displays the pid of processes started [on hold]

I found the next exercise : write a script called find-pid.sh that gets the full path parameter to an executable and displays all process PIDs started using that executable. PIDs will be displayed ...
1
vote
2answers
43 views

Copy a folder overwriting ONLY smaller files in destination

I have tons of PDFs in multiple sub-folders in /home/user/original that I have compressed using ghostscript pdfwrite in /home/user/compressed. ghostscript has done a great job at compressing about 90% ...
0
votes
4answers
65 views

How remove duplicate names and print array after unique names

How to collapse KO categories with the same name and print gene names that were assigned to each category in array, as in example below. I have this: K00002 gene_65472 K00002 gene_212051 K00002 ...
3
votes
3answers
391 views

Command not working properly in shell script

Here is output of: sudo iwlist scan 2>/dev/null | grep ESSID | sed 's/.*ESSID:"\(.*\)".*/\1/' 2>/dev/null Yash Shah CoreFragment CoreFragment_5G CoreFragment dlink Yash Shah COMFAST ...
0
votes
1answer
32 views

rsync not quitting and running next rsync

I have a shell script that has 6 rsync commands. What it should do is run the first and then move on to the next. However, what it does right now is do the first once it is finished it'll hang and ...
1
vote
2answers
61 views

how to copy data from multiple txt to a single txt file according to the order [on hold]

I have used the code cat *.txt >> output.txt . This code is doing is its work but here unix is deciding the order in which the files are being copied to my output file which is undesirable as i want ...
-3
votes
2answers
47 views

sort abc.log | awk 'LAST != $0 {print}{LAST=$0}' How does awk LAST work? [on hold]

sort abc.log | awk 'LAST != $0 {print} {LAST=$0}' this awk command how to delete blank lines and duplicate lines? In fact, I want to know how "LAST != $0" and "{LAST=$0}" work.
3
votes
1answer
45 views

How to run script at start when everything is up and running?

I have a PC for routing purposes, it has 2 network interfaces and runs Debian. I want to add a sound to it, to signal that it is booted and okay. So I've created some /etc/init.s/beep-startup script, ...
1
vote
0answers
24 views

Order of kernel upgrade commands for gentoo

I have simple bash script to update the kernel. It includes building the kernel, rebuilding external modules, building initramfs with genkernel and updating grub config, here is the script: #!/bin/...
0
votes
2answers
28 views

How to remove trailing CR quickly?

This is my source file, it dumps a database into a JSON and worked great with Debian wheezy: #!/bin/sh echo "Status: 200" echo echo { printf ".mode csv\nselect * from cfg;" | sqlite3 /home/ftproot/...
1
vote
1answer
21 views

Can I create BASH function that will hold text block that can then be called for output to FILE and SCREEN to cut down on code block repetition [duplicate]

I have a BASH utility that outputs measurements to screen live as it runs and writes the result to file at the same time. I am having to repeat the same code twice (see below). Once to write to ...
0
votes
1answer
35 views

facing error as syntax error near unexpected token fi' [on hold]

#/bin/sh file="C:/khushal/prop.txt" if [ -f "$file" ] then echo "$file found." while IFS= read -r key value do key=$(echo $key | tr '.' '_') eval ${key}=\${value} echo "User Id ...
0
votes
0answers
20 views

Get output of server crash from server re-spawning script

I currently have Homebridge set up on my raspberry pi. When the pi boots, it starts a script which attempts to keep homebridge alive. I originally took the script from this answer which walks you ...
0
votes
1answer
25 views

Get HTTP header response with telnet in shell script using a proxy

I need to get the http header response from a server (google) with telnet, as i don't have curl or wget in my busybox environment. Also, I'm behind a proxy. So on the command line I can successfully ...
-3
votes
0answers
23 views

Download files from file list wget

I have a file where are written downloading links Google.com/image2 Google.com/image3 Google.com/image4 Google.com/image5 Google.com/image6 i want to download all of them with scripts. If the name ...
4
votes
2answers
328 views

Find only GUIDs in file - Bash

I have a file that might contain GUIDs (their canonical textual representation). I want to do an action for each GUID in the file. It might contain any number of GUIDs. I have already a file ready ...
0
votes
2answers
53 views

Having nothing on stdout when executing awk script [on hold]

I run a awk script. But, it is here. This is the command awk -f awk_scr ERR.txt. BEGIN { FS=" " target="missing" } { for (i=1; i <= NR; i++) { for(j=1; j <= NF; j++) { if ($j == target) ...
0
votes
1answer
39 views

Spaces after io redirection operator? [duplicate]

I've noticed that when writing a shell script, there's a lot of inconsistency in whether people put a space after the I/O redirection operators. For example: foo >bar.txt Will work, but so will ...
0
votes
1answer
30 views

Need to associate one field with another in event, using bash script

I've gotten most of what I need done, but am stuck at the last part. I need to download the campaign from this month, but the url is associated w/ a campaign id and not the month (makes sense). I need ...
0
votes
1answer
64 views

BASH logic problem; difficulty testing one string variable with IF and OR

I have a string var1 which I am using in BASH. It can be three values var1=on var1=off or var1 can be equal to anything that is not on or off I wish to build an if statement in BASH that tests $...
-2
votes
2answers
36 views

Shell script to display files system which uses more than 5% disk storage

[![enter image description here][1]][1] How the grep command works in this script? I have this many file systems (refer image) and I want to execute the script in such a way that it works based on ...
0
votes
4answers
72 views

How to compare the content inside a txt file?

I have a txt file which named as output.txt: output.txt 2128,4.4 2128,5.5 I wish to have a compare script that first line first number before comma is equal to second line first number, then it ...
1
vote
1answer
244 views

Error [: -lt: unary operator expected in shell script Linux [on hold]

I get error [: -lt: unary operator expected after run below script, anyone can share ideas? temp=0 while [ $temp -lt 25 ] do sleep 1 echo "running.." if [ $temp -eq 5 ] then ...
0
votes
0answers
27 views

After SSH not able to read the input from the keyboard and display on the screen

#!/bin/bash server=(*.*.*.*) echo "Connecting to IP : $server" ssh -i dotestnet root@${server} " echo "Present Working Directory : $pwd" echo "Deleting existing packages...." rm -rf ~/transactions rm -...
0
votes
0answers
30 views

How to wait for the execution of a python script inside shell script?

I want to mount another root partition, edit the grub.cfg file with a python script and afterwards umount the partition again. How can I wait for the python script to finish and check if the partition ...
1
vote
1answer
39 views

Infinite-loop shell script in tmux status bar

I wrote a bash script to display cmus status in tmux status bar. It has worked fine for a while, but recently after a fresh reinstall of Debian 9 tmux displays <'path/cmus-status.sh' not ready> ...
1
vote
1answer
34 views

What's the best way to automatically edit GRUB configuration after boot?

I am using a dual boot setup of Arch Linux and Ubuntu. GRUB is installed on the Ubuntu partition and this leads to unwanted changes to grub.cfg after installing updates from within Ubuntu (...
1
vote
1answer
46 views

How do I find the display number of the X server currently using the physical monitor / running in the active virtual terminal?

I'm in the process of making a x11vnc launching script that would fix the dreaded black screen that prevents you from using VNC until reboot. So far, I've managed to find a workaround by using the ...