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
1answer
59 views

Passing comma separated variable to remote SSH Session

I am trying to read comma separated variable in shell script and splitting it like as below while [ -z "$variable" ] do printf 'variable: ' read -r variable [ -z "$variable" ] &...
0
votes
1answer
18 views

Umount: target is busy to variable

I want to check if a USB is busy and store the result in a variable: $ foo=$(umount /dev/sdb1) $ umount: /path/mounted: target is busy. But when I want to print $foo, I get an empty variable $ echo ...
1
vote
1answer
25 views

rsync fails only when initiated via cron

I'm attempting to rsync files to my local machine from a remote server on boot via a crontab entry. My rsync script waits for resolv.conf to be configured by DHCP processes, then begins the rsync. ...
-1
votes
2answers
32 views

If id = s001, then do

My variable id cuts the names of every subject. I have specific commands for each one, so I want to say: if [[$id = s001]]; then do something. End if [[$id = "s002"]]; then do something else. End ...
1
vote
2answers
60 views

Looking for command line package for showing inline text-based menu selector with arrow keys

I'm looking for a tool for displaying inline menus in the shell which can be navigated with arrow-keys and enter. By "inline", I mean that the menu is displayed within the normal flow of stdout text, ...
0
votes
1answer
38 views

.sh Script to find and delete folders of a variable name

I have a very unique issue whereby when I have certain Macs accessing our Synology NAS the Mac (Via Office 2016) create temporary files like in the screenshot. These files are related to the Office ...
0
votes
1answer
37 views

how to add timestamp to stdout and stderr from a crontab job?

I want putting timestamp traces into two different files when I call to the script from a cron task. One file is for stdout script.log and another for stderr script.err With this cron line I get ...
-2
votes
1answer
50 views

Bash Script - Automatic fill the given password when prompt for password [closed]

When i run a certain command written in aa.sh bash file through aa.sh and then command terminal ask for password to continue execution like sudo password or git remote password to authenticate. My ...
0
votes
1answer
49 views

Cron entry to pass the value to script

I have a script(main.sh) which calls another script(Get_Files.sh) and gets a value in a variable like the below: File_to_Refresh="$(sh /Aug/work/Get_Files.sh /Aug/Work/Universal_File.txt)" Now I ...
0
votes
1answer
24 views

Multiple conditions are not working in while loop in Shell Script

I am trying to do multi condition check i.e., the input should not be empty and it should contain only numbers in while loop in Shell Script but i am facing multiple errors while trying to perform ...
-1
votes
0answers
66 views

Moving files between RHEL and sFTP returns permission error

I have specific group of files which I want to move to sFTP directory from RHEL machine. file1.csv file2.csv file3_20190808.csv Public RSA is stored on sFTP, private key is in my .ssh directory. ...
0
votes
0answers
11 views

Using until loop to wait for resolv.conf configuration [duplicate]

I’m writing a simple script to rsync some files from a remote server on boot via crontab. Unfortunately, this is being run before resolv.conf is configured. I’m trying to use an until loop to sleep ...
0
votes
2answers
52 views

Way to execute a shell script by event

Is there a way to trigger a shell script by event not by time (cron)? For example, when the disk is full it will run a shell script to remove old logs. Like in windows, task scheduler triggered on an ...
1
vote
1answer
58 views

How can I get feh to set wallpaper to each monitor according to its size?

I have a directory filled with png files $ tree ~/wallpaper/ ~/wallpaper/ ├── foo--1366x768.png ├── foo--1920x1080.png ├── foo--2048x1080.png ├── foo--3440x1440.png └── foo--3840x2160.png 0 ...
1
vote
0answers
13 views

Piping data from FFPlay requires me to cat the pipe for the program to start

#!/bin/bash ICECASTURL=$1 nohup ffplay -autoexit \ -nodisp \ -i $ICECASTURL -af astats=metadata=1:reset=1,ametadata=print:key=lavfi.astats.Overall.RMS_level \ &...
1
vote
1answer
73 views

How to create a google contact from command line?

I can use goobook to create a google contact with NAME and EMAIL but I need to add a PHONE.
3
votes
1answer
57 views

How to use variable in sed command

I am trying to delete two lines ( 7 and 8) from a .txt file. For this I am using following code:- #!/bin/sh Column="7" sed '"$Column",8d' myfile.txt > result.txt on running this script, I am ...
0
votes
2answers
47 views

Backup Work dir to git before shutdown

I am using Ubuntu 16.04. I have a directory named Work which I want to backup to github everytime I poweroff my computer. I have written the backup script and it's working fine but I cannot run it ...
0
votes
1answer
39 views

Condition check in if statment [duplicate]

Here is my bash script while ./clipnotify; do SelectedText="$(xsel)" CopiedText="$(xsel -b)" Check="$(xclip -selection clip -t TARGETS -o)" if ["$Check" != *"image"*]; then if [[ $...
5
votes
3answers
210 views

pruning subdomains of other domains in a file using script (bash, awk or similar)

I have a huge size file (ten thousand entries) comprising of domains (in random order, but no duplicate domains and with an arbitrary number of subdomains), here is a little example: domain.com ...
0
votes
0answers
30 views

How to use `find` command with a directory starting with special characters [duplicate]

I am writing a script which takes a directory name from user, then find files inside it. The script may fail if the user use some special characters with their directory name. $ var="-foobar"; $ find ...
0
votes
3answers
55 views

Setting shell variable before command gives 'command not found'

I am trying to set a shell variable and pass it into a command as part of a Shell script with the following code: SLS_DEBUG_TEXT="" if [ "$ENABLE_DEBUG_LOGGING" = "true" ]; then SLS_DEBUG_TEXT="...
1
vote
1answer
51 views

how to make the inner loop faster?

I created my first shell script few days ago and while testing it during creation on few files, it worked flawlessly. However now in practice, I have over 12000 files to edit with it and it is going ...
0
votes
1answer
46 views

Shell script loop while not reading [closed]

I'm trying to figure out the best way to halt a running script using a keyboard shortcut while the terminal is not the active window. This led me to learn about watching keyboard events with cat /dev/...
-4
votes
1answer
63 views

I want to understand one parse logic for one function in shell script

I am not able to understand below function. Can someone please explain me? skusep="_" pudhlbl="npu1" createPUDH1Mapping() { prodMFile=${1} ${AWK} -F";;;;" -v apudh1b1=${pudh1b1} -v ...
0
votes
2answers
33 views

sed substitute one line into a part of the next line

I have input like this: *123456789 This is a <secret> Other stuff here. *987654321 This is a <secret> Other stuff here. where "Other stuff here." could be one more lines, but the number ...
0
votes
2answers
68 views

Bash script which compares number obtained from a cut

I have a string like this "Hello catch these numbers 20 30" And I have: NUMBER_ONE=$(echo "$line" | cut -d' ' -f5) NUMBER_TWO=$(echo "$line" | cut -d' ' -f6) When I compare if [ "$NUMBER_ONE" -gt ...
1
vote
1answer
42 views

how to execute file i created [closed]

i have a code like this echo "test test1 test2" > /storage/emulated/0/log.txt and i want read and verify that code, use command cat -n /storage/emulated/0/log.txt > /storage/emulated/0/...
0
votes
0answers
15 views

Why a result from history command doesn't behave in a bash function? [duplicate]

I started learning bash script recently, and I got stuck with this situation. I want to use a result from history command for some purpose. First, I tried to extract the 2nd column (command name) ...
0
votes
1answer
30 views

Automatically paste commands in multiple processes of a screen session

I have several bunch of commands writen in bash contained in a text file, separated by \n\n and I would like to automatically paste each in given screen processes. For the sake of clarity, let's say ...
0
votes
0answers
22 views

how to get first modified date and last modified date of files in single directory and store in variable in linux shell

I want to zip all files from single directory and rename zip file with first modified date and last modified date from zipped files. For example I have files from monday to saturday, and I would zip ...
0
votes
1answer
70 views

I am creating directories using shell script and i am using 'chmod g+s' permission on the directory but the recursive permission is failing [duplicate]

I am creating directories in a shell script with below permissions chmod -R 770 /user/mydir chown -R user:mygroup /user/mydir chown -R g+s /user/mydir However whenever I am creating a new directory ...
0
votes
2answers
35 views

How to sort videos by codec and execute a command

So I have been trying filter out H265/HEVC and only show videos that are not the previous codec and then execute a command that I have that will transcode the video using my settings. Every time I ...
1
vote
1answer
29 views

Unix2Dos Sub-directories with file rename

I'm looking for the best way to handle essentially performing a Unix2Dos on all files with a certain extension .nux. I actually want to rename the extension to .nun. Right now my code manually ...
0
votes
1answer
28 views

Bash, export, “-n” for simple command concatenation drops the '-n' [duplicate]

I'm not finding this answer, and it's got to be obvious, but I still need the help. In an attempt to create a command line option, I was using the various flags and echoing them to verify they were ...
0
votes
0answers
37 views

root command are not executed in ssh remote script [duplicate]

i have 10 clients linux machines and i want to change the hostname and creat a linux user automatcly , i creat this script : #!/bin/bash ADDRESS=`cat /home/admin/Documents/host.txt` USERNAME=client ...
1
vote
1answer
35 views

start and end time of 200 log files

I have around 200 directories. Each directory contains only one log file. first line of log file specifies the time the particular job start and last line the job end time. I can export the ...
2
votes
3answers
59 views

How can I substitute a text that is inside single quotes on multiple lines using command-line tools?

I have a script that has a $variable storing a text with an undetermined number of lines. Let's say I've named it script.bash and it's located in $HOME: #!/bin/bash # commands on the beginning of my ...
0
votes
0answers
28 views

Problem in bash script and logging function

I have 10 servers, which are accessible from the main server. My bash script is running on the main server, which logs into all the server's and executes some commands. The script at some point of ...
1
vote
1answer
22 views

Supressing specific error throws from a bash script

I am using a library that throws a reasonable error when called upen and completes the desired action such that my outputs are as expected. However, as other people will use the script, I think the ...
0
votes
1answer
33 views

Script Integer getting prefixed with "

I am running a jar file using a very basic shell script (I literally just need this to run on startup of a NAS). However, I am getting some rather unexpected behavior: Script looks like this: java -...
0
votes
0answers
43 views

Split tuple and get N-th element

I need to split the tuple value returned from python script and get particular value (in my case an array) and assign it to the bash array. Tuple returned from python: (1,2,[3,4],[5,6]) # ...
0
votes
1answer
42 views

Running script from different user

I want to run a script from a different user without logging into it. I don't have permission to edit sudoers file nor do I have root access.
0
votes
0answers
18 views

'unbound variable' error when using function-level bash trap (trap … RETURN)

Consider this script that calls into a function that sets up a trap for the RETURN of that function: #!/usr/bin/env bash set -euo pipefail function f1() { local temp_file temp_file="$(mktemp)" ...
0
votes
1answer
37 views

bash file contain executable/binary code

I found this tool and when I downloaded it is a bash executable that contains binary code. First of all I didn't know this is possible. Does anyone know who this can be done? Also I am not sure how ...
0
votes
1answer
24 views

Cut string on every nth line of a very large document

I have document A here: @rand1 ABCDEFBHIJKLM + <<///// @rand2 NOPQRSTUVW + <<//<<< @anotherrand XYZABCDE + <<//<<< I would like to have an output that contains ...
2
votes
1answer
68 views

sed: -e expression #1, char 37: unterminated `s' command

Hi I'm trying to change the content of the multiple files in the folder. I encountered sed error while trying to iterate through array where I store names of the files I need to edit. I tried to use ...
0
votes
1answer
24 views

Unix or linux segmentation error

While running program i got coredump error.but in my source coredump file is not reflecting.please tell me where to see core dump file names.
3
votes
2answers
67 views

Parsing csv file to filter rows basing on a matching set of characters from a column value

Consider the following csv file: A,3300 B,8440 B,8443 B,8444 C,304 C,404 M,5502 M,5511 The real csv file is really big (around 60,000 rows) but I only included a small version for ...
3
votes
2answers
88 views

Search For Three Consecutive Words

There are duplicates in my booklist (txt file) like the following - The Ideal Team Player The Ideal Team Player: How to Recognize and Cultivate The Three Essential Virtues Ideal Team Player: ...