1
vote
1answer
35 views

Why does the same sed regex (after grep) fail when run in a bash script vs bash command line?

Here's the script. It is successful when I run it from the BASH prompt, but not in the script. Any ideas? When I say "fails," I mean the sed regex doesn't match anything, so there is no replaced ...
0
votes
3answers
50 views

How to count number of instance of a word starting at another word

I need to grep the MySQL-error log starting at today's date formatted like: `date +"%y%m%d"` (140710) And look for all instances of the word partitioned. I've tried various things to no avail. ...
2
votes
1answer
42 views

diff two directories for changes and format output to use for script

I currently try to monitor two directories and subdirectories for changes in files. The directories contain the same set of files, some of them are changed. So I thought I might use the diff command ...
2
votes
1answer
131 views

What is the difference between filename=${1:-/etc/hosts} and filename=/etc/hosts? [duplicate]

What is the difference between filename=${1:-/etc/hosts} and filename=/etc/hosts? For example: filename=/etc/hosts if [ -r "$filename" ] && [ -s "$filename" ]; then md5sum $filename ...
0
votes
2answers
76 views

set variable options with dot

I'm trying to interface with a system not managed by me that is doing some Unix command scripts and command to easily execute a job. There is a variable substitution that doesn't work and I wonder if ...
2
votes
4answers
105 views

How to initialize an array using awk and bash?

I am trying to store values of the first line of a text file into an array. Here is what I have so far: arr_values=() awk ' NR==1 { for (i=0; i<=NF; i++) ...
2
votes
4answers
233 views

Inserting a line in a file only if this line isn't yet part the file

Total newbie to shell scripting, I am searching to create a script to automatically apply some custom configuration to text based configuration files. In the present case, I am searching to add 2 ...
1
vote
1answer
34 views

Why isn't this XMLStarlet Query Working?

I'm trying to write a simple bash script that parses price info from the ebay developer API search results. Here's an example of XML search results for "Detective Comics 700": ...
0
votes
2answers
25 views

Write log for a false statement of an if condition which returns exit 2

I have a script running every 5 mins with two exits in a condition clause. #!/bin/bash date=$(date +%Y) if [ $date -eq '2014' ] then echo "Current year is $date" exit 0 else echo "Current ...
2
votes
1answer
53 views

SSH Command behaves differently in Expect Script

I'm using this command on Server1 ~# ssh root@Server2 /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys to append the contents of Server2's id_rsa.pub to the authorized_keys of Server1. It ...
3
votes
3answers
135 views

Howto run interactive commands, as another user

I'm trying to write a bash script that context switches to another user (root, in this case) executes a set of commands to i. create a user (interactively prompting invoker for username) then ii. ...
3
votes
2answers
57 views

Error when calling mv with wildcards

#! /bin/bash error_text=$(tail -n +1 /path/dir/folder/exc/a/update/Abd/ER/* | \ grep 'Warning\|Loaded\|Event') echo $error_text nc 10.10.99.45 25 << EOF ehlo mail.abc.pvt mail from: ...
3
votes
2answers
64 views

Checking the status of custom services with a script

I have a handful of shell scripts that start WebLogic managed servers. I need to design a master script that does the following: Executes the shell script for a component\managed server Checks to ...
0
votes
1answer
49 views

Is there a way of copying only directories and not files in bash? [closed]

I want to copy only directories from a folder on a remote server to my server. Is that possible? Here is the code I have so far but it copies files and folders: scp -rq ...
0
votes
2answers
60 views

Simple Script to setenv tcsh or export bash

I am having problems with simple scripting, my Box is CentOS so bash is the default shell, now I wanted to send a line via setenv (tcsh) and would like to make a script that will ask me to input a ...
1
vote
2answers
86 views

Changing user to root when connected to a linux server and copying files

My script is coded in a way that doesn't allow you to connect to a server directly by root. This code basically copies files a server to my computer and it works but I don't have access to many files ...
2
votes
3answers
90 views

Need help to combine 3 split lines of bash script into one single line

The following is what I found after googling: dpkg --list 'linux-image-*' \ | perl -ane 'BEGIN { $r = `uname -r` or die; chomp $r } print $F[1], "\n" if $F[0] eq "ii" && $F[1] !~ ...
1
vote
3answers
209 views

How to capture error message from executed command?

I was tasked to create an automated server hardening script and one thing that they need is a report of all the output of each command executed. I want to store the error message inside a string and ...
1
vote
1answer
44 views

Can't spawn backgrounded process

My team's using Pallet (think Puppet in Clojure) to automate server provisioning, but running into a fairly fundamental problem: Pallet can execute arbitrary scripts directly on target VMs, but if one ...
4
votes
1answer
38 views

Memory consumption of a script

Is there way to check the memory (physical & virtual) consumption of a script, of course in the moment of its execution. Calculating the used memory minus the used memory before and after the ...
7
votes
2answers
300 views

Check bash/shell script dependencies

Is there a method/command to check for the dependencies of a bash script? In other words, a response to this question : Which libraries should a user install to run the script? I can do this ...
1
vote
1answer
138 views

Create a iptables rule if the rule does not all ready exist

Hi I've created a script to setup Nagios on my remote servers. My Script checks iptables to see if a firewall rule all ready exists and then is supposed to add the rule if it's not all ready there. ...
2
votes
1answer
23 views

Script. How to sort and move catalogs

I have some trouble writing a script. I don't know how to sort and move catalogs. #!/bin/bash while read -r line; do mkdir "sd/$line" done < 1a.txt After reading information from 1a.txt ...
0
votes
2answers
59 views

Different forms of executing a shell script

There are a few similar questions around that I've already seen, but I've come up with something different. I'm reading this http://www.tldp.org/LDP/abs/html/invoking.html and I got confused when I ...
5
votes
1answer
133 views

Save password in bash script for multiple queries

I would like to know if there is a safe way to only be queried for a password once in a custom bash script, and then save it somehow to be used for later needs. At the end of the script it should be ...
2
votes
2answers
33 views

Capture transcript of program with redirected input and output

A typical interaction for a program I've written might look like this: Enter command: a_command Completed a command Enter command: another_command Completed another command I typically run my ...
2
votes
1answer
46 views

Beginner question about bash “for loop”

When I do, for ((i=0; i<"${ARRAY}"; i+=2)) do echo $i echo ${ARRAY[$i]} done echo $i works as I expected, also echo ${ARRAY[0]} works, but with $i as iterator i see only blank lines. How ...
4
votes
4answers
323 views

Bash Scripting : Printing column data in the same row

I have written a bash script to calculate the size of a PostgreSQL database and print the output along with the date when the script was executed in a text file. The script code is as follows: ...
3
votes
2answers
51 views

Bash script : help file inside the script or in a different file?

I'm writing a script that has the vocation to be a fully featured program at the end. As far as I know, BASH is enough for his purpose (manage PPA's, kinda like Y-PPA). I would like to know how to ...
5
votes
1answer
188 views

When is it important to write portable scripts?

Most code I write is in PHP. I have recently started learning shell scripting. Most of the resources and tutorials that I've come across are specific to Bash. Some warn about bashisms and some don't. ...
3
votes
3answers
423 views

How can I extract/parse a complete URL from a semi random string?

I'd like to have bash parse/extract a full URL (and only the url) from a random short string. Examples: bob, the address is http://www.google.com or https://foo.com/category/example.html is up ...
6
votes
2answers
313 views

What's the most efficient way to grep for two completely separate things and assign the values to separate variables?

CentOS 6.x I want to take the output from curl, grep for two completely separate strings, and assign their respective values as variables. What is the most efficient way to do this (without writing ...
20
votes
2answers
612 views

How do I move all files output from a command?

I have this grep command to find files without the word Attachments in them. grep -L -- Attachments * I want to move all the files that are output from that command. How do I do that in bash? Do I ...
0
votes
1answer
59 views

Prompting when redirecting content of script to remote machine

I have simple script: #!/bin/bash while getopts ":u:" opt; do case $opt in u) USER="${OPTARG}" ;; \?) echo "Unknown flag has been used: -$OPTARG" >&2 exit 1 ...
7
votes
1answer
206 views

Parallel execution of bash script

I have a table URL_Experiment in my database (mySQL database). I have 2 million URL links in this table. For each URL, I am checking if some particular text is present in the URL and updating the ...
1
vote
2answers
54 views

Make Trickle get the correct $PATH

Trickle is a bandwidth limiting program. I have the following script for trickle. #!/bin/bash echo $PATH trickle -s -t 3 -u 200 -d 200 "$@" I have a script in ~/bin/ that want to run the script ...
2
votes
1answer
57 views

Why does AWK not like dots in one of two substitutions?

I'm trying to use AWK in a bash script to look for a placeholder string in a template file and replace it with the contents of a variable that (can) contain various special characters. Example: ...
2
votes
2answers
2k views

Use awk to split line into array and use that array's values in calling shell

First of all, my apologies for the somewhat clumsily worded title. If you can think of a better one, please feel free to edit. [EDIT: done] What I am trying to do is use awk inside a bash script and ...
1
vote
2answers
896 views

How to check if string starts with value containing #, tab, and maybe space?

In my bash script, I want to check whether a string starts with # modified: or # new file:. In both instances, the character after # is a tab. In the latter instance, the character between ...
4
votes
5answers
1k views

Using $? in an if statement

function foo { (cd $FOOBAR; <some command> if [$? -ne 0] then echo "Nope!" else echo "OK!" fi ) } I am trying to write a function like the one above and place ...
0
votes
1answer
165 views

Can I use an if statement to detect if bash and dash are being run interactively? [duplicate]

After looking around for a while I've found several good pages describing how to check and see if a bash script is running interactively and there seem to be several methods, but one of them that I ...
2
votes
2answers
89 views

How to split files with common prefix in bash

I have a directory with many files with common prefix, like gsc*_other.foo, where * is a character that goes from 0 to 9 or a/b (where a stands for 10 and b for 11). My goal is to create text files ...
2
votes
2answers
82 views

Using Sed with Regex

I would need to edit the values in a file delimited by colons (:) I would like to replace the contents of the file by using regular expression. After a grep to confirm that the item exist in the file ...
1
vote
4answers
396 views

Bash Script to Sort Files into Alphabetical Folders on ReadyNAS Duo v1

I have an old ReadyNAS Duo v1 (Sparc) running an unknown flavour of Linux. I have a folder structure with 1,000+ files I want to move into a folder structure based on the first letter of the file ...
1
vote
1answer
58 views

Bash: show prompts if arguments weren't provided

What is the best way of supporting in the script prompts and arguments at the same time? I want to show prompts if arguments weren't provided. Is there something better/shorter than this? ⇩ ...
4
votes
1answer
167 views

Bash is automatically reloading (injecting) updates into a running script upon saving it: Why? Any practical use?

I was writing a bash script, and happened to updated the code (saved the script file to disk) while the script was waiting for some input in a while loop. After I returned to the terminal and ...
3
votes
2answers
844 views

How can I print only certain commands from a bash script as they are run?

I have a bash script with various if statements based on command line arguments I pass in when calling it. Having some kind of output as to what commands are being run is helpful to confirm the flow ...
0
votes
2answers
205 views

Convert perl script to bash

The following script it's about monitoring some logs, the $timestamp is at log at every line that something happens. Example: 03:19:13.4 Begin summary update for ...
3
votes
3answers
876 views

Understanding boolean operators in bash script

phone_missing=false echo "missing $phone_missing" if [ ! $phone_missing ] then echo "Lost phone at $readabletime" $phone_missing=true fi I just can't wrap my head around this, as ...
6
votes
4answers
844 views

Intersection of two arrays in BASH

I have two arrays like this: A=(vol-175a3b54 vol-382c477b vol-8c027acf vol-93d6fed0 vol-71600106 vol-79f7970e vol-e3d6a894 vol-d9d6a8ae vol-8dbbc2fa vol-98c2bbef vol-ae7ed9e3 vol-5540e618 ...