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
0answers
10 views

shell script to copy file from one server to another based on argument

This is a shell script to copy file from one server to another using sftp. When we are executing shell script we are passing one parameter as a argument and it must use this parameter to identify the ...
1
vote
1answer
25 views

How to read dd/mm/yyyy date string in date -d UNIX command?

I am trying to dynamically convert one column in text file containing date in dd/mm/yyyy hh:mm:ss format to yy-mm-dd hh:mm:ss. Following command is working but giving output in yy-dd-mm and NOT yy-mm-...
-2
votes
0answers
13 views

Which startup script should I use?

I have heard of a number of places to put scripts to run at startup: /root/fw.start /root/scripts/fw.start /etc/profile.d/* /etc/bash/bashrc /etc/init.d/* /etc/rc.d/* /etc/default/rc* ~/....
0
votes
0answers
10 views

Parallelize with SGE_TASK_ID

I have a block of code that works as I want it to but is really inefficient. for f in *.GeneSet; do #Figure out the cell type by removing "Genes.GeneSet" from the end of the filename cell_type=${f%...
0
votes
1answer
19 views

Find Consecutive error in file and list file names

I got this project to analysis my logs where i need to find any consecutive errors occured more then thrice and list logs name . As i logs were huge , i wrote below script to help myself. for i in `...
2
votes
1answer
325 views

Find fails if filename contains brackets

I'm trying to use find inside a loop to create a variable that contains a file matching the filename + desired string Example: file1.en.srt file1.mkv file1.pt.srt This is the relevant part of the ...
0
votes
0answers
18 views

How to compare du command output using shell variable [duplicate]

#!/bin/bash var=$(du -s /data/dir1/ | awk '{print $1}') if [$var -ge 5000]; then echo "The size is more $var" else echo "The size is less $var" fi The du command works fine at shell. When I ...
-3
votes
0answers
36 views

Need to optimize this code and make it more compact [on hold]

Need to optimize this code and make it more compact cat failed_degraded_script.sh echo "***Pulling disk states from all frames***" for i in $(cat HPE_FRAMES_IP); do ssh Reports@$i showsys | awk '{...
0
votes
0answers
36 views

How to execute unix command after few background jobs?

My c-shell code has to complete few concurrent background jobs before execution of some unix commands. However, somehow in code my background jobs never returns handle to unix commands. i.e. $cmd1 | ...
0
votes
2answers
33 views

How can i echo the value of [ 4 -gt 3 ] ,that is a test expression in bash?

How can I echo the value of [ 5 -gt 4 ] ,that is a test expression in bash? [ 5 -gt 4 ] | echo and echo `[ 5 -gt 4 ]` both end up printing a blank line @Thomas Dickey 's answer works but could ...
-2
votes
2answers
35 views

Using sed to replace a character before another character in a line

I try to use sed or whatever to replace a number of a line /opt/tin/toss to become a * For example 37 7 * * * /opt/tin/toss 43 7 * * * /opt/tin/te1 58 7 * * * /opt/tin/test2 Output: 37 * * * * /...
0
votes
0answers
29 views

how to control process that killed

we want to know what are the options to control processes , for example /opt/important_script/gate_machine.pl is a script that must be up and running and in case from some reason script killed , ...
0
votes
2answers
30 views

Script runs command fine, but fails when trying to save output to variable

I have a shell script with the following contents. I call it with ./script.sh. Echo successfully runs, but not when I try to save its output to a variable. The same is true for all commands I've ...
0
votes
1answer
61 views

Run bash command from awk system only once

I am using tail -F to monitor a severe weather alert server log file and awk to filter and execute a command if the conditions for an alert are met. I need to execute the bash command(an ssh command ...
2
votes
4answers
52 views

BUILD LOGIC - what could be better than using AWK?

Below is how a log looks like: Company=XYZ Req_id=1234 Time_taken=10 sec Status=Success Company=ABC Req_id=3456 Time_taken=200 sec Status=Failure Company=DFG Req_id=3001 Time_taken=15 sec Status=...
-5
votes
1answer
48 views

Need Desire output using shell [on hold]

I need to get desired output using a shell script. Input: aaabbcaaabbcc Desired Output: a3b2ca3b2c2 Command should print number of occurrence of each alphabet only when it's greater than ...
-1
votes
0answers
32 views

comparing two file in different directory [duplicate]

Hi i have two file location in which /projects/staging/mvn_file_data_001.csv, /projects/staging/mvn_file_data_002.csv, /projects/staging/mvn_file_data_003.csv /projects/staging/mvn_file_data_00n....
1
vote
1answer
28 views

Set to non-default user group upon login in bash

Upon login with .bashrc, how to set the user's group to a non-default one, say targetgroup? Specifically, my problem is that I can execute, on the command line: newgrp - targetgroup but when I ...
2
votes
1answer
28 views

How to Run Program from bash and run scripts inside that program?

My Bash Script: #!/bin/bash cd dataset/ root .x Pushkar_Soni.cpp What I am trying to do is: 1) launch root by command root 2) Inside the launched program root I want to run scripts .x Pushkar_Soni....
0
votes
2answers
58 views

Writing to a file horizontally

I have a script that I want to run and then write the output to a file in a specific format Currently when I run the script and direct it to standard output it gives it to me in the format I want. The ...
0
votes
2answers
53 views

Bash: minus one to the sub string split by separator

I would like to batch rename filenames turning A-B-C#2-D.wav to A-B-C#1-D.wav. So for example: A-B-C#2-D.wav A-B-C#8-G.wav A-B-C6-E.wav becomes A-B-C#1-D.wav A-B-C#7-G.wav A-B-C5-E.wav So the ...
-9
votes
1answer
34 views
0
votes
1answer
53 views

how to pipe two to shell scripts?

how to cut the selected columns from the file. Example: load.sh students.csv | select.sh ‘name’ ‘school_name’ This will output the name and school_name columna from the loaded file to the ...
-1
votes
1answer
15 views

find in a file where sign of a column entry changes and print first line where this happens

I have multiply files, each with three columns. I would like to monitor where a given column entries first change sign (i.e negative to positive) so that I save that row where this first happens to ...
-1
votes
0answers
19 views

How to execute script on remote linux machines [on hold]

I am trying to get df -h output from different Gnu/Linux hosts, and get output to my local host, while all remote hosts have different root passwords.
0
votes
3answers
30 views

Concatenating all arguments of a function/removing all spaces from a variable

What's a good way to concatenate all arguments of a function? What I got at the moment is iterating over them and appending them consecutively: func(){ concat= for arg in "$@" do concat=$concat$...
0
votes
2answers
15 views

How to store the output of calculation to variable using bash script [duplicate]

I want to do a simple coding by storing the product of calculation using command bc into variable. answer="$varnameX % $num1" | bc echo "the result is $answer" it did not show the product of ...
1
vote
3answers
36 views

Script with more than one flag

I am trying to create a script that lowercases/uppercases files or directories. modify [-r] [-l|-u] <dir/file names...> I am currently using getopts to check for flags. However, I can't run ...
0
votes
2answers
76 views

validation of records [on hold]

I have two types of files located in two different directories which /projects/staging/mvn_file_data_001.csv /projects/staging/mvn_file_data_002.csv /projects/staging/mvn_file_data_003.csv ... /...
0
votes
1answer
24 views

Run A Script Every X Minutes for Y Minutes [duplicate]

Good morning ! I am trying to run the following script every X minutes for Y minutes. Basically, this script outputs a logcat for 5 minutes and checks for files older than 30 minutes to remove them. ...
1
vote
5answers
42 views

creating new columns

i have two input files like this file 1 a 1 b 2 c 3 d 4 file 2 a a b c c c d d how can i create a shell script to have the following output a 1 a 1 b 2 c 3 ...
0
votes
1answer
36 views

Bash Script to create a DMG

I am trying to automate (using bash script)creation of JHFS+ formatted,DMG file on a macOS. The script should be able to intake user supplied: size of the DMG in GB's destination of the DMG type of ...
0
votes
2answers
26 views

Batch 7zip all files separately in a directory (Centos 7.6)

I am trying to 7zip all files inside a directory separately into their own archive (for each file) in Linux Centos 7.6. Been looking around for a while but never found a method.
0
votes
1answer
46 views

parse JSON data using jq and convert into csv

I am downloading api json data and converting into my final result as a csv file. The sample data is in the below form: { "content": [{ "Title": "abc", "brand": "xyz", ...
1
vote
2answers
24 views

Looping over files with specific matching numbers

I'm using a Bash script, and I have two input numbers. For simplicity, let's say the first variable is called Start and the second variable is Stop, and each can be a number between 1000 and 2000. I ...
2
votes
3answers
41 views

Execute permission NTFS data partition

I'm trying to execute some scripts, which are located on my data partition, from the shell, but I have a problem with permissions. bash: /media/storage/ss/script.py: Permission denied Before ...
1
vote
1answer
38 views

Reading any error in log for last 5 mins only

This is how my log file looks like: 2019-03-17 13:49:01.267 MESSAGE Web 2019-03-17 13:50:04.325 ERROR error msg: ConnectivityException 2019-03-17 14:15:20.326 ERROR error msg: Error occurred ...
0
votes
1answer
23 views

Generating a ssh Host config file out of a Supperputty XML file

I am building a script that generates an ssh config file out of a Supperputty XML Session config file. I don't know which tool could handle it better. I try to achieve it with awk, but I don't receive ...
1
vote
1answer
36 views

Calculate difference in numbers and save in colon-separated time format with bash script

I have a tab-separated file, e.g., 0018803 01 1710 2050 002571 0018951 01 1934 2525 003277 0019362 02 2404 2415 002829 0019392 01 2621 2820 001924 0019542 01 ...
0
votes
2answers
20 views

How to detect NTFS/exFAT filing system type fronm script

User has a (incremental) backup script using rsync, to external device. This was erroring on an SSD he had. Turns out (I had no idea) his device was formatted exFAT. Unfortunately that means I need ...
0
votes
2answers
32 views

Count number of occurrences of a pattern on same line

I need to solve this in a shell script. I am counting number of occurrence of the abc string below and I want to get the answer as 3. echo abcsdabcsdabc | grep -o abc abc abc abc ...
0
votes
3answers
42 views

new line not append instead append on the end of the line

we gave the following config file ( config.txt ) more config.txt export var1=345476746 but when I am appending new parameter as echo "export var2=5645" >> config.txt we get more config.txt ...
0
votes
3answers
66 views

FOR loop: pass 2 variables from a file simultaniously

I am writing shell script, to extract 2 variables from a file, and have used below FOR loop. for i j in `cat list` do echo title echo total "$i" "," "$...
1
vote
1answer
30 views

bash + write standard output and error to both logs

in my bash script I use the following approach in order to write every thing from standard output and standard error to log.txt export LOG=/tmp/installation/log.txt exec > $LOG 2>&1 so ...
2
votes
1answer
38 views

How to make alias interpretive?

I have a list of servers I often connect to, named like server001, server002... server999. I don't want to store 1000 alias hardcoded with these server names. I also don't want to write a function and ...
0
votes
2answers
43 views

bash remove members Slack from channels using xargs and sleep?

I'd like to be able to remove a batch of people from a "private" Slack channel. Use case: whoops, I just added 137 people to the wrong channel! The Slack Member ID list is obtained from an Airtable ...
0
votes
1answer
31 views

Specific fields from macOS Command “diskutil apfs list”

would appreciate inputs on the subject. I have the output from the macOS (High Sierra;FileSystem :APFS) command - diskutil apfs list. Sample output is given below: +-- Container disk5 1B5FE22B-6F4F-...
0
votes
0answers
24 views

How to run my wallet script in background? [closed]

I am developing cardano webservice so that i have .connect-to-mainnet wallet script to run api but i have to write every time on command line this following command ./connect-to-mainnet but I want to ...
0
votes
1answer
18 views

Get the path of sourced bash script [duplicate]

There is my simple script that I try #!/bin/bash DIR="$(cd "$(dirname $0)" && pwd)" echo $DIR When I execute it like $ ./my_script.sh, get the path correctly. But, when I source it ...
0
votes
2answers
47 views

How do I get a shell script to remove duplicates in a text file, based on the 11th 21st columns?

How do I get a shell script to remove duplicates in a text file, based on the 11th 21st columns? Sample file: Header:0000000000000001457854500000 XP 12345678912yeyeyeyeeye 0000003 XP ...