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

learn more… | top users | synonyms (2)

0
votes
2answers
30 views

Is there a unix scripting file checking Key?

I hate to post such a stupid dumb question but is there a key that explains theese letters such as -n, -d, etc all mean ? I'm not sure how to ask the question so its best if I just explain what i'm ...
0
votes
0answers
12 views

How to time the execution of parallel commands

I am trying to write a bash script that launches n commands in the background and then waits for each command to finish. I can easily get the time it took to execute all the commands using time sh ...
0
votes
1answer
14 views

How can a script tell if Platform LSF is available in an environment?

We have some shell scripts that presently utilize Platform LSF to manage job execution. These scripts will eventually be migrated to an environment that uses a different job scheduler. During the ...
0
votes
1answer
39 views

SSH to server and execute and print commands

I am newbie to shell and Unix. I have a server AA and from the shell script have to connect to server BB using ssh. On server BB, I want to check if the given folder is empty or not, if not empty it ...
0
votes
0answers
22 views

Bash associative arrays only storing last value [on hold]

I have made a recursive function which is meant to count the number the of hidden directories and files and normal directories and files, but this isn't the problem. I want the function to also store ...
3
votes
2answers
63 views

How can I run two commands in parallel and terminate them if ONE of them terminates with exit code 0?

I have 2 commands which are to be run simultaneously. And I want the script to terminate if one of them either exits with code 0 or 1. How can I achieve this in Linux(Ubuntu) cmd1 & cmd2 & ...
0
votes
1answer
16 views

Accessing function parameter instead of command line parameters [on hold]

I have a function search defined in my_script.sh. Within the script I want to call the function with a parameter. search() { echo $1 } search functionParam I call the script like this ./...
0
votes
1answer
17 views

How to store output of awk to array with empty string on null values? [duplicate]

I have a variable animals. animals=lion*tiger*elephant**cat***dog I just want to split by the delimiter * and store it into an array. Expected: animals[0]="lion" animals[1]="tiger" animals[2]="...
1
vote
1answer
26 views

Getting user input from script used as stdin for SSH session [duplicate]

I have a shell script which runs commands and asks for user input. The script is located on my computer. I'm using the script as stdin for an ssh session to execute commands remotely. The problem I'...
3
votes
1answer
167 views

Bash Parameter Substitution: command line vs. script

I am practicing with parameter substitution in bash. I wrote the following dummy script: #!/bin/bash var1="/some/path/to/file/the_file.arbitrary.n.ext.0.random.ext" var2="/some/path/to/file/...
0
votes
1answer
33 views

sort all last 3 columns based awk [on hold]

I have an Excel file like this 11 45 478 G:0.990244 A:0.00731707 G:0.1243902 I want to sort all last 3 columns based on one threshold like $6<=0.1 by using awk
0
votes
2answers
27 views

How to find and substitute contents for multiple files at the current directory using shell script or linux?

I have the current folder name as details1 and the current folder has list of files like file1, file2, file3 and so on... Example:(Here I had showed only the file1 and other files will also contain ...
0
votes
3answers
48 views

Elegant solution to echo to either stdout or file in bash

I have a bash application that is producing some result, and I'd like to echo the result to either stdout or to a user chosen file. Because I also echo other interactive messages going to the screen, ...
3
votes
1answer
58 views

Ask for hostname in a shell script?

I have a script that ask if the ping of a certain array of macs is online. #!/bin/bash #Array of Mac hostnames separated by spaces my_macs=( Mac111 Mac121 Mac122 Mac123 Mac124 Mac125 Mac126 Mac127 ...
0
votes
2answers
57 views

move only uniq files from one directory to other [on hold]

I want to move files from directory A to directory B. But there are some conditions. directory A structure: a.txt_20170502 b.txt_20170502 a.txt_20170507 asd.txt_20170509 asd.txt_20170522 So, I ...
1
vote
5answers
66 views

While loop taking a longer time to complete

I am using the below while loop to read a file. while read file do FileFound="`find $DataDir -name $file -print 2>/dev/null`" if [ -n "$FileFound" ]; then echo $FileFound >> ...
3
votes
6answers
76 views

Running a command multiple times with arguments (filenames) from a file?

I have a file with a long list of filenames (with full paths). I've also got a program I'd like to run multiple times, using one and one filename from this list as argument. The program I'd like to ...
0
votes
1answer
27 views

Bash-Script is not executing command, but if command entered manually, it works

this is my bash-script: #!/bin/bash sleep 3 sudo apt-get update && echo 'y' | sudo apt-get upgrade cd /opt/ sleep 5 wget http://dl.4players.de/ts/releases/3.0.13.6/teamspeak3-...
0
votes
1answer
39 views

Need to remove a specific column in a CSV

Example input: A0021,,Outside state ambulance serv,I,,0,0,, A4217,,"Sterile water/saline, 500 ml",X,, A4672,,"Drainage ext line, dialysis",X,, Example output after first sed command sed -i 's/("[^,...
0
votes
1answer
32 views

line 13: syntax error near unexpected token `(' [on hold]

Running shell to string together several csv files, ran this process before the end of the year and ran fine, running today after only making the edit to include 2017 and receiving the above mentioned ...
0
votes
2answers
50 views

“merge” the contents of one shell script file into another

Having a "library" with constants and functions (lib.sh), I can include it in my script (script.sh) . /myfolder/lib.sh ...... Is there a way to merge the included file in the script (i.e. replace ./...
4
votes
2answers
44 views

Interrupting a for-loop in bash, but only after an iteration is completed?

Is there a way to interrupt/stop a for-loop in bash, but only after the current iteration is completed - ie. "between" done and do? I'm running a for-loop on several directories, with a command ...
0
votes
0answers
16 views

busybox linux - firewall rules script

My vision is this: I want to keep track of outgoing packets started by computers on my local network and whitelist IP addresses that they go to. Everything else I want dropped. My reason is this: ...
1
vote
1answer
35 views

bash is eating my string

Consider this short program: #!/bin/bash ARDUINO_SERIAL=arduino-serial/arduino-serial PORT="/dev/cu.usbmodem1421" VERS=$($ARDUINO_SERIAL -q -b 9600 -p $PORT -S 'V' -e '\r' -r) echo --- VERS = $VERS ...
1
vote
0answers
20 views

Forwarding an email AS AN ATTACHMENT with a bash shell script, or applescript

I am a complete newbie to shell scripts and applescripts but would like to forward email AS AN ATTACHMENT, to satisfy my ISP's (Comcast) rules for sending them spam email to be blocked. There is a "...
16
votes
3answers
2k views

Are if else statement equivalent to logical and && or || and where should I prefer one over the other?

I'm learning about decision making structures and I came across these codes: if [ -f ./myfile ] then cat ./myfile else cat /home/user/myfile fi [ -f ./myfile ] && cat ./myfile || ...
0
votes
1answer
11 views

FFMPEG Merging Script Error

So I have an almost working script for FFMPEG that merges an .aif and an .mp4 file with the same name into a single filename_output.mp4 but when I execute it I get a weird error saying that a file is ...
0
votes
1answer
38 views

Help needed for Subshell for Bash Script [on hold]

I want help for the sub-shell of shell-scripts. Sub-shell commands must be execute automatically within bash scripts. It runs automatically then executing the sub-shell within the bash but it ...
-1
votes
0answers
20 views

How to detect USB drives with specific label?

I want to run a script when a USB drive with specific label have been detected.
0
votes
2answers
41 views

How to batch rename files and convert datestamp from DD-MM-YYYY to YYYY-MM-DD?

I am trying to rename a folder with files which contain a datestamp like this: string_DD-MM-YYYY_hhmm.pdf to this format: string_YYYY-MM-DD_hhmm.pdf so that they sort by date when sorted by ...
3
votes
3answers
436 views

Error “syntax error near unexpected token `('?”

What's in my terminal bash: settings64.csh: line 35: syntax error near unexpected token `(' bash: settings64.csh: line 35: `foreach i ( $xlnxInstLocList )' Portion of the script set xlnxInstLocList=...
0
votes
0answers
16 views

Generate dictionary based on random word [duplicate]

I'm trying to teach myself a bit more Linux scripting and gave myself a challenge of generating a random word and then having that word defined. Right now this is what I have: #!/bin/bash word= shuf ...
0
votes
1answer
19 views

Copying a text file into a calculation sheet with a script

I would like to create a script that can write up from a text file a LibreOfficeCalc or equivalent table with the same columns than the following those from the following lines from a text file : [1] ...
0
votes
1answer
37 views

Generate E-Mails with content on different files

i am using a script to create a random password for a user. The file looks like user1:password1 user2:password2 user3:password3 Passwords are openssl passwd hashed. I have an own file where the ...
0
votes
1answer
10 views

shell script run by xautolock keeps stall value in command substitution

I'm trying to make a simple script to put my computer to sleep if it runs on battery unattended. I have this simple script: #!/bin/sh if [ `cat /sys/class/power_supply/ADP1/online` -eq 0 ]; then ...
-9
votes
0answers
40 views

can anyone write shell script for this question? [closed]

i wanna ask that F1 file should create automatically and the offsets should cpy into another file F2 with bytes and its size.? #!/usr/bin/sh echo "******DD with functional scripts..******" for((i=0;...
-3
votes
2answers
39 views

cd to variable not working in shell script

I have following variables $a=/opt $b=var $c=usr $path=/$a/$b/$c/man when I do cd $path it says no such file or directory. but this path actually exist /opt/var/usr/man .. any suggestion ?
2
votes
2answers
28 views

Weird output when using ssh inside a loop over a file

The script is to read a file that contains multiple lines, each line containing a tab-delimited array. I want to execute some remote commands that take those array elements as arguments, with sudo ...
3
votes
1answer
49 views

Bash remove all characters after pattern with awk

I have an input file in the following form: something here somethingElseHere^[%-somestuff here ^[%-somestuff here Note that ^[ is the escape character \x1b. So what I'm trying to do is delete ...
0
votes
1answer
40 views

using cd command and few other commands after ssh

I am trying to run 3 to 4 commands after doing ssh in a script. can you please help me out with this. Since, it says, it cannot access the directory. tfptools@tfpwltst01:TEF_PERU:tfptools> vi ...
0
votes
2answers
27 views

append files base on a list

I have a list that corresponds to a file. These files have to be appended to a single file based on their order on the list. order.list: FLORIDA #corresponding file is florida.txt ...
0
votes
0answers
49 views

Need awk one liner for a report [closed]

Need an awk one liner for the following report Input: # cat a.txt 2.5.5,CRITICAL 2.6.2,CRITICAL 2.6.3,MAJOR 2.6.8,CRITICAL 2.6.9,CRITICAL # cat b.txt 2.5.5,PASS 2.6.2,FAIL 2.6.3,PASS 2.6.8,PASS 2.6....
1
vote
1answer
49 views

Why is this Error "line 26: Syntax Error near unexpected token 'done'?

for (( i=1; i<= $numberstudent; i++ )) do head -n $i fullstudentsMarks | tail -n 1 > $(cut -f 2 -d ' ') npassed=0 sum=0 average=0 for (( j=3; j<= 10; j++ )) ...
1
vote
2answers
67 views

mv command to move and rename set of files

I am using mv command to move a set of files from one folder to another that involves renaming the files also. mv <SRC_PATH>/ABC_$t1.dat <DEST_PATH>/ABC_$t1_$$.dat I am using the ...
-2
votes
2answers
28 views

add new data into existing file

how do you include additional data into existing file? Example File1 : Apple Pear Orange grep 'Pear' File1 >> File2 INdate=`date +'%m/%d/%Y' File2 Output : Pear 12.14.2016 How do i get ...
0
votes
2answers
16 views

How do I pass variable value as bracket expansion sequence value?

The code block in particular is: for n in {1..$PASSEDARGS}; do printf "%s\n" "$n" done The following code block doesn't work, instead it prints {1..3} where 3 is the value of the number of ...
0
votes
1answer
36 views

how to remove newline characters in fasta sequence

I have fasta file (modelfasta.fasta) like this: >seq1 AAAAAAAAAAAAAAA GGGGGGGGGGG >seq2 TTTTTTTTTTTTTTT CCCCCCC I am expecting output like this: >header>seq1 AAAAAAAAAAAAAAAGGGGGGGGGGG &...
0
votes
0answers
21 views

Can't print entire list of error in a unix command [closed]

I am trying to print the latest weblogic log file, and I am able to do so. But, when I am trying to print the entire list of error, or exception. I cannot do so. Instead, it prints only few lines of ...
0
votes
1answer
50 views

How to use ssh in a function(bash)?

I am trying to execute few commands in a server by logging in using sshpass command like below. SSH_ARGS='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -q' sshpass -p 'password' ssh ${...
-2
votes
1answer
39 views

Combining three scripts [closed]

I need to combine the below script. They are separately working fine. If any one condition success then need to ignore the remaining two. a="primary" b=`virtinfo -a |grep name |'awk' '{ print $3}'` ...