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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [shell-script]

A shell script is a script written for the shell, or command line interpreter, of an operating system.

2
votes
0answers
23 views

How do I transpose a table with repeated key values?

I have a table that looks like this: Column A | Column B 10 | 0.1 10 | 0.2 10 | 0.3 20 | 0.4 20 | 0.5 20 | 0.6 I need to transpose ...
0
votes
1answer
22 views

cp command not executing after running other script inside bash script .

There is cp commands inside my shell-script after following commands echo 'Starting Jboss server !!!' (eval "sh standalone.sh --debug") cp /soure_file_path /target_path sleep 60s sh ...
0
votes
0answers
22 views

How can I run a script with the currently opened URL as an argument in Firefox? [on hold]

Suppose Firefox is visiting a URL http://example.com/some/sub/page. Assume further that you have a bash script myscript.sh which takes a URL as an argument. How can I define a keyboard sequence in ...
1
vote
1answer
9 views

Opening a URL from the terminal in different spaces macOS

If I run open https://example.com from the terminal and then switch to another space with a safari window open and run the same command, the safari window in my current space will just get focused and ...
0
votes
1answer
25 views

Script to move files that match part of anther files name

I am trying to figure out how to write a script that will take files like this: img123 img123back img124 img125 img125back img126 img127 I need to move all the files that have the same number as the ...
0
votes
1answer
12 views

Shell scipt: get filename from *.zip file and save it into a variable [closed]

I have a zip file in a folder and the name of the zip file is always different, but there is only one zip file in each folder. I want to get the filename of this zip file and put it into a variable in ...
1
vote
2answers
20 views

how to rename all files under folder with specific extension name ( recursive approach )

we want to rename all files under /home/DB_home ( recursive ) so every file under DB_home will rename with .txt extension example before change /home/DB_home/hg/ir/qemu-ga /home/DB_home/td/...
0
votes
1answer
27 views

how to delete all files that are old then X days and ended with number/s

we want to delete all files that ended with number with digit or more as 2 digit or three digit and so on note - when files is ended with number , its tell us this file was rotate and actually backup ...
0
votes
1answer
23 views

SCP off the most recently modified file in a remote directory

Is there a simple command to SCP the most recently modified file in a directory on a remote host? I can figure out how to do that from local to remote... something like: scp ``ls -Art | tail -n 1\`` ...
0
votes
0answers
14 views

Shell script to get ip of list of domain names: connection timed out; no servers could be reached

I have the following script from some sources in the web that should execute command host to get the IP address of a domain name in file myfile.txt. The script is: #! /bin/bash while read hostname; ...
0
votes
1answer
27 views

How to output a particular word in file, if it is present?

I am making a simple script where i turn true to false if true is present in file or vice versa if false is present in file, details here. Now i want to output, what is the value after change ie if i ...
0
votes
1answer
38 views

How to exchange two patterns in place with `sed`?

I am using sed command to change <active>true to <active>false in an xml file. Now if I use sed 's/<active>true/<active>false/g' file.xml > file.xml it completely erases ...
0
votes
1answer
25 views

envsubst a yaml file that uses identation

This is a kubernetes yaml config map apiVersion: v1 kind: ConfigMap metadata: name: $CONFIG_NAME namespace: processing data: configuration.json: | { "test" : $TESTOBJECT } And ...
0
votes
1answer
30 views

How to create multiple html tables from multiple csv files using a shell script

I have two csv files like this: test1.csv: user size aaa 10 bbb 20 ccc 30 test2.csv: name value www 5 mmm 8 ppp 9 I want to convert this to two separate HTML tables using a shell ...
1
vote
1answer
43 views

urban legend : why is it better to avoid using file descriptor 5?

In the answer to this question, the answerer quoted a block of scripts, which contains a line like this exec 4>/path/to/output.file #and a third, for reading and writing, with FD 6 (it's not ...
0
votes
1answer
76 views

How to replace a character in an interval delimited by two other characters from a file

I have to replace all occurrences of the vertical bar character | with a comma , when they appear between [ and ] characters, on each line of a file. Let's say I have the below string in the file: ...
0
votes
0answers
23 views

How can I use rsh and mrsh vice versa between OpenSuse 15.0 (nor rsh) and an old Suse (no mrsh)

I am using OpenSuse 10 ... up to 15.0 and I need to run remote comands in scripts with rsh. But on 15.0 there is no more rsh available (just mrsh). I found a compatibility package but I still can´t ...
1
vote
0answers
44 views

Tools for converting 8-bit C1 control characters to ESC sequences?

The ECMA-48 ("ANSI escape sequences") standard describe two ways of encoding the C1 set of control codes: using 2 character ESC sequences, or alternatively, using 8-bit control characters. Wikipedia ...
1
vote
1answer
144 views

Script to remove all, BUT retain one latest backup file of all sub-directories

The following script works for single folder, but I want to iterate through all subdirectories. ls /home/user/Desktop/cron_database_hourly/*/*_[012][0-9]*.zip | head -n -1 | \ while read -r f; do ...
-1
votes
0answers
37 views

Find all (Live) IP Addresses on a CentOS 7.3 Machine

I'm running under CentOS 7.3 and using the Bash command line I would like to accomplish two things: Get all IP addresses associated with any physical NIC (whether or not that physical NIC has an ...
0
votes
2answers
31 views

ubuntu script to retain only latest file of each folders and delete everything else

We have a script which takes hourly backups and stores it inside a folder created as today's date. #CRONJOB TO BACKUP DB HOURLY DAY=$(/bin/date +%d%m%Y) TIME=$(/bin/date +%H%M%S) if [ ! -d /home/...
0
votes
2answers
61 views

how to extract json file using awk/sed?

Input data.json { "lastUpdateTime" : "2018-07-20T10:56:26.000Z", "items" : [ { "date" : "2018-07-19T21:09:27.000Z", "user" : "dddd", "size" : 5219402, "rawSize" : 15658206, "...
0
votes
1answer
37 views

Can't Export in Powershell

Am new to PowerShell, and I'm trying to make a simple script that lists all folders and files in a drive that shows the last modified date and the size and then export them to a cvs. so far I have ...
11
votes
2answers
2k views

How to edit Excel file (xlsx) using linux shell

Is there a way (tool) to edit XLSX files using Linux shell? What I need is a way to remove the last three not empty rows from the first worksheet. I know that XLSX is just a zip file, packed with ...
0
votes
3answers
65 views

Quit loop if a key is pressed

I want to exit the script if any key is pressed. #!/bin/sh while true; do df -h | head sleep 10 clear done Any suggestion?
1
vote
1answer
19 views

Handle filename with blank in shellscript

These are my folder structure. [set symbolic links here] /links/ [entity] /data/a 1/ #(folder name has blank) /data/b 1/ /data/c 1/ /data/d 1/ . . . I want to made symbolic link for each ...
0
votes
0answers
44 views

How to wait until services are ready

I have been setting up a Jenkins pipeline using docker images. Now I need to run various services like MySQL, Redis, Memcache, Beanstalkd and Elasticsearch. To wait the job until MySQL is ready, I am ...
0
votes
2answers
60 views

Why does FFmpeg add a second subtitle to my files, even though I explicitly only added one?

I have a bunch of MP4 files and subtitle files in a folder, each following the pattern of episode[num].mp4 and episode[num].ass. I wrote a small shell script to automate combining those into MKV ...
2
votes
1answer
48 views

How can I call a batch file within another batch file?

trying to call a batch file within another batch file the script completes the synchronization of the remote folders but then fails to call the other batch file. @echo off "C:\Program Files (x86)\...
0
votes
1answer
63 views

can't increment a variable inside a loop in a bash script

I am running a bash script in Ubuntu 18.04. The script needs to run a python script 10 times. I did the following testbash.sh script: #!/bin/sh count=1 while [ $count -le 9 ] do python /home/e/...
0
votes
1answer
57 views

How can I copy(or move) and rename multiple files from different directories using the unix cp command?

Let's say, under this directory: /home/data/ There are 100 folders, the name of these folders are 24538_7#1, 24538_7#2, 24538_7#3 ... to 24538_7#384. In each folder, there are many files and ...
1
vote
1answer
27 views

I have 2 versions of the same shell script. ASCII wise they are Identical, but only one executes correctly

I have 2 version of the same shell script file. ASCII wise they are Identical (Used Notepad++ Compare Plugin), but only one executes correctly. I ran FC /B on the windows command line to compare them ...
0
votes
1answer
52 views

How create name value pairs array from command line arguments?

Consider example: bash myScript.sh --name1 valule1 --name2 value2 Inside myScript.sh: java -jar someJar. jar --name1=valule1 --name2=value2 E.g. array --name1 valule1 --name2 value2 needs to ...
1
vote
1answer
56 views

Running functions that were declared outside my shell script

Currently my ZSH has some sourced functions, for instance: % declare -f ... a lot of shell functions appears here. I'm currently writing a shell script that will call a specific function from ...
5
votes
3answers
815 views

How to sort files into folders, according to file names - Windows CMD

How do I sort files into folders, according to file names, using CMD / PowerShell commands? Let's say I have a folder containing a large amount of files (more than 20,000 files), where all the files ...
0
votes
0answers
7 views

How to create a tree structure in comand line that displays only the background processes/jobs

I want to know how can I create a process tree structure that displays only background processes. I've tried with pstree, but I'm not sure I can specify this condition for pstree; I think it's a bit ...
0
votes
1answer
39 views

using logical AND within IF statement to search for file ext(tilde ~)

Please find the below script : #!/bin/bash for index in `ls -1 /appdata/frozen_files` do for bucket in `find /appdata/frozen_files/$index -name "*.gpg~" | cut -d/ -f4-5` do for files in `ls /...
1
vote
1answer
38 views

Not Terminating EOF with sshpass

Below is my script code: sshpass -e ssh -o "StrictHostKeyChecking no" voltdb@$DB_SERVER_IP /bin/bash << EOF cd voltdb/bin echo "ReInitializing VoltDB, Wait for 5second" ./voltdb init --force ...
2
votes
4answers
363 views

How to replace whitespace with underscore in all filenames?

The script given below places "underscore" instead of "whitespace" in all file names that are in a certain folder. I'm having trouble making a shell script that places "underscore" instead of "...
2
votes
1answer
324 views

wget without keeping the cache

I'm trying to run a remote bash script hosted on github: wget -O - https://raw.githubusercontent.com/xxxxx/script.sh All works good, no problems But when I update the script above, and I run the ...
0
votes
1answer
253 views

BASH - Count the number of occurrences of a substring in a string

How can I count the number of occurrences of a substring in a string using Bash? EXAMPLE: I'd like to know how many times this substring... Bluetooth Soft blocked: no Hard blocked:...
0
votes
1answer
56 views

Extracting system info in one go from ec2-instances

I have almost 150 ec2-instances in an account. I want to extract some system info from each instance. I am aware that I can individually login into each system and get the information using the ...
0
votes
1answer
16 views

ending txt contents in csv file by placing values in column format

I would like to get help on sending below txt contents in csv file by placing values in column format DEV-C axpp4-pkrisbtm 04-25-2018-01.15 04-25-2018-01.20 UAT AXKIN-PBBCT4 04-25-2018-22.02 04-25-...
0
votes
1answer
28 views

ksh - Reading an unset variable into an array using the read command

I have the following ksh script, where $an_unset_var is an unset variable which is being used for the first time: read -A arr <<< "$an_unset var" echo ${#an_unset_var} echo ${#arr[*]} ...
3
votes
1answer
63 views

Add specific text in every blank line

I've a file as below abc pqr xyz aaa bbb ccc I want to add specific text like "this is test" in every blank line like below abc this is test pqr xyz this is test this is test aaa bbb this is ...
0
votes
1answer
221 views

syntax error near unexpected token `>' in script run by cron

I'm writing a shell script for Mac OS/Linux. The script is run by a cron job. I'm trying to append stdout and stderr to a log file. My command(simplified) looks like this(line 5 in myscript.sh): ...
1
vote
0answers
60 views

Find out the real path of a file from a SUBST drive

Is it possible to find the real location of a file, knowing its location on a drive created with subst? Example: > subst d: c:\dir\ > real_path "c:\file" c:\file > real_path "d:\file" c:\dir\...
3
votes
1answer
46 views

Arg handling in a script for a modified “find” function?

I'm using FreeBSD and I understand and use the -prune option on find to prevent the command descending into a subdirectory. But I find the necessary syntax very clumsy and awkward. It also doesn't ...
1
vote
2answers
27 views

Replace slashes in a url

I'd like to replace all slashes from a web address. Example address: https://example.com/sub/folder/files/file.txt Expected result: example.com-sub-folder-files-file.txt I can strip the https but I ...
0
votes
0answers
15 views

How do I lock out a PCIe device easily?

I'm not looking for anything super complex like SRIOv, but just a semaphore. I have a build machine with mulitple concurrent users. I want to have a simple lock mechanism for a PCIe device (we have ...