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

learn more… | top users | synonyms (2)

-3
votes
0answers
20 views

Bash Script problem with Variables from files [duplicate]

Trying to get this script to work how ever I get an error no matter how I try to set the varibles. After checking the varibles are not being set from the files that the information is in.
-4
votes
2answers
33 views

Linux Bash script fails with a syntax error

Trying to get this bash script to work: #!/bin/bash for result in $(cat ./fn7); for dip1 in $(cat ./fn4); for dip2 in $(cat ./fn5); for dip3 in $(cat ./fn6); for ip in $(seq 0 255); ifconfig > ...
2
votes
3answers
84 views

Replace values in file

I have a files: $cat file1.txt 1234|W 1345|S 8427|D 2132|C 3243|V and my sql file is : $cat select.sql SELECT * FROM CUSTOMERS WHERE ID IN (FLAG); and I have a shell with the next ...
0
votes
0answers
22 views

I'm able Start Service With init.d script, however doing service <service name> start does not work

I'm able to start a service with an init.d script, however doing service <service name> start does not work. For e.g. /etc/init.d/haskal start, the service is starting fine and service haskal ...
3
votes
1answer
52 views

Create table with frequency of unique names retrieved from multiple .csv files

I have 32 CSV files containing fetched information from a database. I need to make a frequency table in TSV/CSV format, where the names of the rows are the name of each file, and the names of the ...
0
votes
1answer
20 views

shellscript is having trouble finding a file [duplicate]

I have a shellscript that is having trouble finding a file. The text file exists so I don't understand what the issue is. #!/bin/ksh goodmain $1 | sed -e '1,/mmxxaa/d' $ ls -l total 1364 ...
0
votes
1answer
53 views

Running .sh Script With Sudo Results In Different Output

I'm seeing some really strange behavior in a script I'm working on.What I have is an svn hook that gets run whenever a commit is made to an svn repo. It runs a sqsh command that generates another ...
0
votes
2answers
50 views

How to fix vmware header error?

I'm trying to run vmware on my kali linux 2.0 box, because I want a lab to practice my skills on, but vmware won't launch it's giving my an error message saying "C header files matching your running ...
0
votes
1answer
38 views

If else statement involving two numbers in scientific notation [duplicate]

I have two numbers in scientific notation and I want to do some comparison between them in an if statement in bash. While doing so, I am getting error like bwlow: E.g: bash-4.2$ a=10e-12 bash-4.2$ ...
0
votes
1answer
40 views

Script too slow ? Any particular reason?

I have a script which does hexdump along with pipeline commands and finally I am redirecting it to a file. Now I am logging data from the serial port of my Raspberry Pi. I also call a python ...
0
votes
1answer
34 views

command /opt/bin/date --date '-15 minutes 2016-04-27T14:14:47' producing result many hours before stated time

I'm using the following command in an attempt to work out the time 15 minutes before the timestamp: /opt/bin/date --date "-15 minutes 2016-04-28T16:58:55" '+%Y-%m-%dT%H:%I:%S' The problem is the ...
2
votes
4answers
47 views

How to catch and handle nonzero exit status within a Bash function?

Say I have the following (pointless) Bash function: myfunc() { ls failfailfail uptime } I run it as follows: myfunc || echo "Something is wrong." What I want to happen is ls runs (as ...
0
votes
1answer
28 views

Correct syntax for inputting date variable into date calculation code

In my script, the following code successfully produces a timestamp variable for $n in the format 2016-04-28T15:47:48 for n in $(perl parsetime.pl | sed "s/.....$//") do echo $n result is: ...
1
vote
1answer
61 views

Escape strings to be posted via curl

I am trying to make a script that takes some atom feeds and posts them to slack through the Slack API via curl. What I have now works for simple texts, but some of them have double quotes or & ...
1
vote
3answers
56 views

how can we use multiple variables in single for loop in shell script?

I am implementing as below code using for loop but wrong output coming after running the script. for i in `awk -F"|" '{print $1}' $INPUTFILE`, j in `awk -F"|" '{print $2}' $INPUTFILE` do echo $i:$j ...
1
vote
2answers
37 views

loop create from file

I have a file(test) It contains two columns and two lines pippo mm pluto tt I would like to create directory,owner and create password I do some think like that while IFS= read a b; do mkdir ...
2
votes
1answer
38 views

How do I check for the existence of a process without a failed exit code being returned?

I’m using Amazon Linux. I want to start a process provided one isn’t running already. This is a bash script I embed within a Jenkins Maven job. So I have pids=$(pidof /usr/bin/Xvfb) if [ ! -n ...
0
votes
1answer
36 views

unzip without replacing original file and report to log

I want to write a bash script to decompress a file without overwriting the original one and redirect the operation result into a log file. I found an answer to the first part of my question at: How ...
1
vote
1answer
37 views

cannot get screen command to execute code containing DISPLAY=:0

I am trying to ssh into a remote machine and run a shell script, which opens a GUI. I want the GUI to open on the remote machine and remain open (so I am using DISPLAY=:0 nohup). I tried: ssh -t ...
0
votes
1answer
22 views

Dynamically write bash script from another?

I am trying to dynamically create and write to a file a bash script from from a current bash script. echo "## Get the IP of the system that was assigned #!/bin/bash ip=$( hostname -i | xargs ) echo ...
0
votes
1answer
21 views

Including milliseconds in a Script?

sudo hexdump -v -e '1/1 "%02x\n"' /dev/ttyUSB0 | awk '$1=="ed" { getline byte1 getline byte2 number = strtonum("0x" substr(byte2,2,1))+2 ...
0
votes
1answer
16 views

Setting XDG_CACHE_HOME Breaks Firefox Installation

In my .bashrc I set my XDG_CACHE_HOME variable to "~/.cache/". This breaks my Firefox installation, telling me that it cannot load my profile. Without this line, Firefox loads properly. I have ...
0
votes
1answer
21 views

printf in my output now

The encryption on this problem just got more interesting. I started with this script: while read CTFlist; do #next we need to create ctfs padded with zeros as a variable ctfPadded=(printf ...
-1
votes
1answer
56 views

add multiple .csv files using bash command

I want to iterate over all randomly generated CSV files in a folder using using bash and add them line by line. Each CSV files has 3 rows, the 1st row indicates just the number of generated files and ...
-1
votes
2answers
43 views

Use of && and || operators to handle the result of the same command

In bash, is it possible to use these two operators to handle both of the exit statuses of the same command ? or if I want to handle both cases, I have to use an if statement ?
0
votes
3answers
49 views

sed substitution

I have a string as follows: /test/test/ 12 /test/test My goal is to turn it into: /test/est/ 12 /test/test This is the command: echo "$x" | sed 's@\(/*/\).@\1@g'" I am using at the moment but ...
2
votes
2answers
315 views

How can I redirect the output of a child process?

I am running the following git clone command through sudo and bash and I want to redirect STDOUT to a log file: % sudo -u test_user bash -c "git clone https://github.com/scrooloose/nerdtree.git ...
0
votes
1answer
34 views

getting links including outer html

From a html page with lots of links, I'm looking for a way to extract only the links that follow a specific format. <a href="https://always/same/link/same-name_19.html">always same ...
-1
votes
0answers
29 views

Shell Script- Conversion script for reading and updating data to new column

I am writing a conversion script that will help me to read the data from a column and move it to a new column. I want to read data row by row for column cross_reference and copy this data to newly ...
0
votes
2answers
47 views

Binding Timestamp with Hexdump?

I am running a script which is given below, sudo hexdump -v -e '1/1 "%02x\n"' /dev/ttyUSB0 | Many Pipes | gawk '{ print strftime(":: %s"), $0 }' Here the data is being hex dumped with timestamp ...
0
votes
3answers
44 views

BASH: pass arguments to sub-script

I have a script like this: #!/bin/bash . config ./sub-script There are a lot of variables in config and I don't want to pass them to sub-scirpt like ./subscript arg1 arg2 ... arg100500. Also, I ...
0
votes
0answers
32 views

How can I create a script to do not mount pendrives for some time?

I'm new to Linux (I'm using Ubuntu 14.04) and I want to create a script to deny pendrive mounting. What I want: root user deny pendrive mounting to everybody except him for 4 hours. More: how to ...
0
votes
5answers
71 views

Adding time stamp to a log file?

I am running a script file. I have written a while loop inside the script in which I have pipelined multiple commands like awk, sed and finally I am writing the output to a file using > operator. I ...
0
votes
1answer
33 views

Bash script using mysql command with variables failing

I have a script to clone a vhost and associated db - however one of the mysql commands doesn't work. It fails and ends up outputting the mysql version number and 'how to use' info as if it hasn't been ...
-2
votes
2answers
65 views

standard deviation using awk [closed]

I am using below command to get standard deviation of file A names 1 2 3 avg 23.3107 20.0372 21.7236 21.6905 awk '{x[NR]=$0 ;} END{a=$4; for (i in x){ss += ...
1
vote
1answer
47 views

Creating a complex variable content by hand

I am creating a shell script dynamically and sending it to a remote server for execution. All is working except when I try to inject a variable with content coming from a file with multiple lines, ...
0
votes
6answers
100 views

how to do formatting of a file in unix

I have a file file.txt. which have below three records. <ResultDescxmlns="http://www.mpaet.com/boe/interface/common">Operation successful. 220095 9251000014 Now my desired format should be as ...
0
votes
1answer
38 views

How to replace a text in a shell executable file (.sh) using Python?

I have xxx.sh file which content is: setsid ./start-meteor.sh >> /home/farah/StudioInstallation/Studio/bricks/platform/log/databricksastro.log 2>&1 < /dev/null & I want to ...
1
vote
1answer
50 views

BASH Variable checker function

I am struggling to figure out a way to reduce code duplication. Specifically when checking if a variable is set. My code currently looks like this: # webadmin enabled if [ -f "${servercfgfullpath}" ...
0
votes
2answers
98 views

Why does `read` not pick up all my vars?

My apologies for the very basic question, but can someone please help explain why the following does not print 3 2 1 6 5 4? echo '1 2 3 4 5 6' | while read a b c; do echo result: $c b a; done ...
0
votes
0answers
56 views

Executing remote code with arguments

Why this: ssh -i ~/.ssh/master.pem ec2-user@xx.xx.xx.xx 'bash -s' < `dirname $0`/elements/"$element" returns hostname.sh test-5000: No such file or directory when $element is not a just a single ...
-1
votes
2answers
82 views

Script that will show area of rectangle

I am looking to write a script which will prompt the user for two numbers, representing the width and height of a rectangle in centimetres, and output the area of the rectangle in both square metres ...
-1
votes
1answer
39 views

Arithmetic expressions in for-loop

In for (( expr1 ; expr2 ; expr3 )) ; do commands ; done expr1, expr2, and expr3 are arithmetic expressions. Is expr1 ; expr2 ; expr3 not an arithmetic expression? (( expr1 ; expr2 ; expr3 )) ...
3
votes
3answers
36 views

How to pass array to bash shell script?

How do I pass an array as a variable from a first bash shell script to a second script. first.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') sh second.sh "$AR" # foo sh second.sh "${AR[@]}" # foo ...
2
votes
1answer
27 views

Bash shell script program that prompts for and reads two integers from the user.

Okay, so I been trying to figure this problem for a while and I'm coming up with errors left and right. This is my first time trying to learn the basics. So any advice would be helpful! Problem: I'm ...
2
votes
2answers
66 views

Accessing array index variable from bash shell script loop?

I want to access the array index variable while looping thru an array in my bash shell script. myscript.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') for i in ${AR[*]}; do echo $i done The result ...
0
votes
1answer
28 views

Automating Backup and Shutdown

I want to backup my entire internal hard drive files into an external hardrive and execute system shutdown once the backup is finished. The reason why I want to do that is to execute the backup during ...
1
vote
1answer
33 views

Join two files in a batch mode

I have many files with the following names: 0001mm.xyz , 0002mm.xyz , 0003mm.xyz ... 0001qm.xyz , 0002qm.xyz , 0003qm.xyz ... I want to join the contents of 0001mm.xyz and 0001qm.xyz ...
-3
votes
0answers
32 views

Checking for sequence of numbers received through stdin in a loop using shell script?

I have a pipe line like this: foo | bar | baz (shell script?) The bar program sends through the pipe to baz a string formed like this: Code: 1 Code: 2 Code: 3 I want to cut "Code" part, collect a ...
3
votes
2answers
73 views

Changing a file's modified date based on date in file name

I have a directory full of photos with file names in this format: IMG-20160305-WA0001.jpg. The date taken is obviously in the file title. Unfortunately the date modified on all files is today. I ...