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

learn more… | top users | synonyms (2)

0
votes
0answers
14 views

Updating environment variable in a shell script

I am trying to update the value of an environment variable in a third party shell script. My OS is Oracle Linux Server release 6.4 (Red Hat Enterprise Linux Server release 6.4 (Santiago). I already ...
1
vote
2answers
32 views

How can I check how many files have been created in one week?

How can I check how many files have been created in one week? Situation: The system will create four files at every week, if the system is running normally. For example: A_08-07-2015.csv ...
-1
votes
1answer
17 views

No such file or directory error when attempting to run shell script upon startup of console [on hold]

I'm trying to run a shell script upon startup in cygwin. I have added these commands to my .bashrc file: $ echo 'export MAIN="D:/dev/Main" >> .bashrc > echo '.MAIN/Env/tpsScripts/devenv.sh ...
1
vote
0answers
14 views

Build Script Help, Not Loading Modules

So I am writing a script to build and install Netcdf, but when I source it, it seems like some of the lines just are not running or are being skipped and I am unsure why. When I run the code line by ...
2
votes
2answers
53 views

Assign variable identifier in loop and echo its value

I hope this question is not a duplicate because I've been trying various ways to solve this problem but couldn't find any solution. I have a for loop in which I'd like to store a command output into ...
1
vote
3answers
52 views

Using a function defined in a parent script

I wrote the following script in the test.sh: #!/bin/sh compare() { if [ $1 != root ]; then echo "Fail" >> CAT1.txt fi } awk -F: '$4 == 0' /etc/passwd | cut -d: f1 | xargs -n1 -i bash -c ...
-4
votes
0answers
27 views

Run DB scripts in linux [on hold]

I want to run DB Scripts in linux but I am not able to do so . Can anyone give me the idea how to run DB Scripts? EDITED as Sybase is used in my project so what "isqlcmd" is doing I want to know?
1
vote
1answer
50 views

Write bash_history to a file with a timestamp

I need help with the script below. The requirement is to capture command line history in a file with specific date and time of commands, when they were executed. The below script captures history ...
2
votes
1answer
39 views

How to read and do a min/max/avg from a NMEA stream

I have a weather station attached to my device spitting NMEA 0183 on /tty/USB0 I have alreeady sorted out how to parse the data and echo what I want in a script. What I need to do now is write the ...
0
votes
1answer
34 views

/bin/sh script error “arithmetic expression: expecting primary: ” + “ ”

ERROR: ./client-disconnect.sh: 22: ./client-disconnect.sh: arithmetic expression: expecting primary: " + " I just need to know how to fix it. It's for user accounting with OpenVPN. Script ...
0
votes
3answers
60 views

Extract numbers from a text file and place them in another file

I have a text file whose contents looks like this: ...
1
vote
4answers
52 views

optimize command with or and pipe to parse the output of ifconfig

I have this command line, but it's doubling the grep and awk ifconfig eth1 2> /dev/null | grep "inet " | awk '{gsub("addr:","",$2); print $2 }' || ifconfig eth0 2> /dev/null | grep "inet " | ...
0
votes
0answers
18 views

How can I use arptables to limit the number of outgoing ARP requests a second?

End goal: Make a script that will limit the number of outgoing ARP requests in a second using arptables. This is to have the ability to not trip the ARP-limiting feature on Cisco devices. I want to ...
1
vote
1answer
20 views

What's the Fedora equivalent of /var/lib/dpkg/info/[…].prerm?

Example file: /var/lib/dpkg/info/util-linux.prerm What's the Fedora equivalent of this file? (Not limited to util-linux - generic question for any package.) Use case: A prerm script is failing. ...
0
votes
1answer
37 views

How to execute R script attaching it to a shell script in Linux?

I am trying to submit a job to be executed on cluster. And this is done by writing an sbatch submission script. The job involves opening R 3.1.3 and running the referenced R script on the server. ...
2
votes
2answers
63 views

Sort files with a specific extension by modified time and store them into an array

I have found many answers to sort the files of directory and even to save them in an array. Sorting Example ls -t Directory listing in array array=(*) My particular problem needs to sort files ...
1
vote
2answers
27 views

Script to Compare the “file size” with “last name of file” and if unmatched delete the file

In my environment, we'll be receiving files from clients into our Sftp. Sftp process the files, and move it to another tool, by appending the file size at the end of the file name. For example, ...
8
votes
1answer
344 views

Are [ “$VAR” = “” ] and [ -z “$VAR” ] always equivalent?

My code looks something like this: VAR="" while [ -z "$VAR" ]; do VAR=$( command | grep "important_string" ) done So I want to poll the output of command, until the important_string appears and ...
0
votes
2answers
69 views

Explain the shell command: shift $(($optind - 1))

I am not a Linux guy but stuck in some Script which I have to read for my Project. So can anyone can help me what this command is doing? shift $(($optind - 1))
0
votes
4answers
91 views

The first Line of Scripting [duplicate]

what does #!/bin/bash at the 1st line mean ? Is it just a comment and ignored by the shell like all other comments in program OR Only this line is interpreted by the interpreter and all the other ...
10
votes
2answers
486 views

Differentiating between running and being sourced in a bash shell script?

Either what I'm asking here is extremely unorthodox/unconventional/risky, or my Google-fu skills just aren't up to snuff... In a bash shell script, is there any easy of way of telling if it is ...
1
vote
1answer
38 views

Pick columns from a variable length csv file

I have two CSV files, which share a column that is unique to each row in each file, like an ID. The files don't have a header. The file_2 has variable length columns e.g. 1,2,3 4,5,6,7,8 I joined ...
1
vote
1answer
47 views

validate the sequence number in the trailer of a file

We have a file that arrives daily and has a sequence number in the trailer like 9999 TR SAP _AP Distribution 0000000000000001 where 0000000000000001 is the sequence number and the file that ...
-3
votes
0answers
25 views

Find the number of jobs present in each box. Find the number of child box in each parent box [on hold]

BOX_A--------------------SUCCESS JOB_AA--------------------SUCCESS JOB_AB--------------------SUCCESS JOB_AC--------------------FAILURE BOX_B--------------------FAILURE ...
-2
votes
0answers
18 views

script to check availability of mail server domain using wget command in solaris 10 [on hold]

#!/bin/sh /usr/sfw/bin/wget --secure-protocol=SSLv3 mail.google.com 2>&1 | awk '/^ /' if [ $? -ne 0 ] then echo "Server is UP" else echo "Error: URL "mail.google.com" is not ...
1
vote
1answer
44 views

Display a line in a text file if variable matches a part in the line?

I'm making a stock checker. I have a file with all of the NYSE exchanges and their descriptions. The descriptions start on the first tab enter of the file. The file formatting looks like this: A ...
-4
votes
0answers
14 views

Shell Script to Generate Automatic ticket/Email [closed]

I have a requirement to generate an auto ticket/email when it's time for a scheduled task to be done and it should repeat again when it's time for performing the task. Could you please help me with ...
1
vote
1answer
38 views

Find last line of a file for matching string?

I want a loop that runs infinitely over a file but always checks the last line to see if it contains the matching string if it does then echo that line and keep the loop running. What I have right now ...
-1
votes
1answer
29 views

Starting Debian mono application (that has a GUI) AFTER boot is done [duplicate]

I've been trying to figure out how to start an application after Debian (Wheezy) is done booting up and on an LXDE desktop session. It is a mono C# application. The script I have is simply mono ...
2
votes
2answers
67 views

Difference of using () and $() to execute a series of commands

I am currently trying to make a script that creates bytes that will be piped as input to netcat. Here is the idea of the script: (perl -e "print \"$BYTES\x00\"; cat file; perl -e "print \"More ...
0
votes
1answer
25 views

Want to use find with rsync in script

I'm trying to make a script that will run in cron, that will search a path for specific file name. In the path there might be more folders with that same file name. If found and they are newer than 2 ...
-2
votes
2answers
45 views

How to make a password box in linux? [closed]

I have a script but can't find mistake: #!/bin/bash data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 dialog --title "Password" \ --clear \ --passwordbox "Enter your password" 10 30 ...
1
vote
2answers
29 views

How do I generate diffs for a series of files?

I have a series of a few thousand files, all with filenames in order, so let's say file1.x, file2.x, file3.x, etc. All these files are in the same directory. I know how to generate a diff from ...
1
vote
3answers
46 views

Killing the previous instances of a script before running the same unix script

I want to kill the background process of the same shell script that i am going to run again. That means before executing the shell script i want to delete the background process running for the same. ...
3
votes
3answers
94 views

How to kill this process in bash

I am trying to interface my homemade Raspberry Pi-powered arcade machine with a coin acceptor, and for that I: use a shell script (named gameplay) which starts the game emulator (MAME) when a coin ...
1
vote
2answers
27 views

bash command/script to reset default route

I manage several OpenWrt (embedded linux) routers for which I've written bash scripts to run an Openconnect VPN client. The client uses "vpnc-script" to set up routing, which replaces the initial ...
2
votes
1answer
44 views

Stable timing for shell scripts?

The run times of scripts vary quite much. I would like to find similar time -function as Matlab's timeit, described here. For instance, I am evaluating these commands here about counting quickly ...
1
vote
1answer
20 views

Conditional file and directory installation in Debian Packages

Is it possible to create a binary Debian package with conditional files and directories installation (e.g. installation of an init script in /etc/init.d/ after being confirmed by user)?
0
votes
1answer
20 views

How to make sure the same string doesn't appear next to itself in an array?

I'm making a Rubik's Cube scramble generator, and the turns can't be side by side or else it's useless. I'm trying to stop it from doing the following: Displaying the same string twice, i.e R2 R2 ...
3
votes
2answers
125 views

To count number of matches in a mega string quickly

I have big text-data without spaces and without other rows in one line. In reality, the streams are 0.2 Gb/s, similar situation here, but in this task, counting occurrences which is more challenging ...
1
vote
0answers
34 views

This code isn't working. (Trying to declare array values in a for loop and do math functions on them)

I was again bored and looked up a list of programs to make in bash, and I'm trying to make a CC (credit card) validator. I had to split the characters into an array to do the validation, and I think I ...
1
vote
0answers
21 views

Exceeding paste's length limits in resulting line? [closed]

I'm in a situation where I am extracting files using Informatica.My problem is that in extreme cases I'm exceeding the maximum length for a resulting line for the header line. I'm on Oracle. What I ...
5
votes
1answer
58 views

Script started as `source` or `executable`?

Can we determine inside the very script whether it started as source (.) or executable (shebang or something alike)?
-1
votes
1answer
55 views

Pass string value to date in Unix

mm="27 Jun 2011" dd=$(date -d'27 Jun 2011' +%Y%m%d) echo $dd I want to use value of mm in second line. When i tried like below dd=$(date -d'$mm' +%Y%m%d) It is giving error.
-1
votes
2answers
45 views

shell script not running using crontab

This is my script mboxutil -l > n.txt sed 's/^.*user//' n.txt > n1.txt cat n1.txt | sed 's/^.//' > n2.txt sed 's/\/.*//' n2.txt > dss_list.txt rm -f n.txt rm -f n1.txt rm -f n2.txt sed ...
0
votes
1answer
50 views

How to extract particular fields from lines using shell commands?

File1: 27/07/2014 10.10.03 Breaker1 was closed by Mr. A.Basu Spectrum ui6dms 29/07/2014 04.50.53 Breaker1 was opened by Mr. D.Gupta Spectrum ui6dms and one note added 30/08/2014 03.20.01 EarthSwitch ...
0
votes
2answers
66 views

What is wrong with the code? [closed]

#!/bin/bash for ((i=1 ;i<=3;i++)) do echo "Enter gallon used(gal):" read gal echo "Enter Miles Obtained(mil):" read mil mileage=`echo $mil / $gal |bc` echo "scale=4; $mileage " | bc c=`echo $c + ...
0
votes
3answers
56 views

Bash: increment a variable in a while loop?

Bash newbie here! I have a bash script that for each file in a set, greps each line in the file for a string. Then it splits the line on commas, converts the 7th element to a float, and increments a ...
6
votes
3answers
276 views

Should I use a slash at the end of path variables in shell script or not? [closed]

Today when writing my shell script. A question suddenly comes to my mind. Since cd /target_dir and cd /target_dir/ both works. Should I add a slash at the end of my path variables in a shell script? ...
-3
votes
1answer
45 views

sed/awk - replace first occurance of a string with array of strings [closed]

I want to find the first occurrence of a word and replace it by 3 strings using sed/awk. for example , I have the below entry in my /etc/hosts file 10.4.16.11 dispatch1 10.4.16.12 dispatch2 ...