Hello, my name is John McPherson. I work for the DOL, in the Uneployment Insurance office, and I am working on an application that uses bash scripts as the controller running the application. I am trying to add a capability to email the output files to the users, which are the states that use the application. The case statement chooses which state to send the email to( or optionally not send an email if state does not want it), is erroring off. I am not sure what the problem is with code. The case statemnet in question is: ## print …

Member Avatar
+0 forum 0

How i can `sed` save pattern matches to variables and do something with it? eg $ echo "string_4.3.2" | sed 's/^string_\([0-9]\)\.\([0-9]\)\.\([0-9]\)$/\1 \2 \3/' output "4 3 2" but I want to pass variables to function eg do_something() { echo $1 echo $2 echo $3 # ..... # ..... } string="string_4.3.2" if [[ $string =~ `sed ??????` ]]; then do_something "$1" "$2" "$3" fi Matched numbers need pasing to method "do_something"

Member Avatar
Member Avatar
+0 forum 1

What it says on the tin. When the system (without logging into X) detects a change in internet accessibility, I'd like to set a hook to execute a script. EDIT: Every single bloody time... So, [dhcpcd-run-hooks](http://roy.marples.name/man/html8/dhcpcd-run-hooks.html) exists... is that the preferred method or can anyone recommend something else that's - in their mind - better? 2nd EDIT: I really am asking these questions. It's just that, in the process of writing the posts, I think of a different way to google the question and the answer magically appears.

Member Avatar
+0 forum 0

Hello everyone. I realize that this may be an elementary question, but all of my searches for answers have not given me a satisfactory result. In my ubuntu server machine, I typed in [after examining my stty settings] `werase='^I'` as I was configuring the terminal to my likings. All was fine after I made that change and the command worked beautifully. After I logged out and logged back in, I could not use that shortcut anymore and I had to manually reprogram it to use it again. Could anyone suggest how I can fix this problem and make the setting …

Member Avatar
Member Avatar
+0 forum 3

Hello Everybody, I am trying to run a simple script to monitor a log file, where I need to send an alarm every time specific line is being written into this log file, currently my script is working fine, the problem is with the miltiple lines that is being written whenever I have a problem with my SW and many lines are logged into this log file which is causing many alarms to be sent, so I am seeking a way to trigger sending the alarm only one time but without existing this script, I need my script to keep …

Member Avatar
Member Avatar
+0 forum 4

garrett@mint-desktop /var/www/html/udemy/php-oop/gallery/backups $ tar --exclude-tag-all=backups -cf lesson20.tar ../* tar: Removing leading `../' from member names I have an empty file called backups in my backups directory to keep the tar file from trying to backup itself. Does anyone know why I'm getting this output? -> `tar: Removing leading ../' from member names` Note that there was a backtick between leading and ../ .

Member Avatar
Member Avatar
+0 forum 5

I have (roughly) the following code: read -p "What is your variable: " WHATIS cat > ./test.txt <<EOF This should be a bunch of lines I want this "variable" to be imbedded it is ${WHATIS} EOF I keep getting the literal output of "${WHATIS}. I did this ages ago but can not remember how or find the code I used. Any help would be appreciated

Member Avatar
Member Avatar
+0 forum 1

I have a C++ program with a main routine which reads arguments from command line: int main(int argc, const char *argv[]) In my system I have defined some aliases in my bash environment which abbreviates directory names. Example: alias dst='home/username/Documents/test' alias src='home/username/Download/test' My program is called "dircopy" and I want to use the following input: `dircopy /home/username/Download/test /home/username/Documents/test` But I want to avoid writing the whole path for destination directory and source directory each time I run the program. Is there a clever way to use the alias definitions in bash when calling my "dircopy"-program ? (Example: dircopy $src $dst …

Member Avatar
Member Avatar
+0 forum 5

Grabs the location and name of the script file itself.

Member Avatar
Member Avatar
-1 forum 3

I am working on a shell script that takes a single command line parameter, a file path (might be relative or absolute). The script should examine that file and print a single line consisting of the phrase: Windows ASCII if the files is an ASCII text file with CR/LF line terminators, or Something else if the file is binary or ASCII with “Unix” LF line terminators. currently I have tried the following code. #!/bin/sh file=$1 if grep -q "\r\n" $file;then echo Windows ASCII else echo Something else fi #!/bin/sh if test -f "$file" then echo Windows ASCII else echo Something …

Member Avatar
Member Avatar
+0 forum 2

A 22 year old vulnerability, yes you read that right, has been discovered which some security experts suggest could be bigger than Heartbleed. The bug, reported as '[CVE-2014-6271:remote code execution through bash](http://seclists.org/oss-sec/2014/q3/649)' relates to how environment variables are processed: with trailing code in function definitions being executed independently of the variable name. This can be exploited remotely with code injected into environment variables across the network. The GNU Bourne Again Shell (Bash) command interpreter is widely used, to put it mildly, and as such is being treated as a critical security risk to Unix and Linux systems. Which means it …

Member Avatar
Member Avatar
+6 forum 18

I am defining the following variables inside a bash script (note: I ultimately want to pass these values to the bash script from the commandline but I haven't gotten that far yet): OFS=',' INPUTFILE='~/data.txt' OUTPUTFILE='~/delimited.txt' FIELDWIDTHS='1 10 4 2 2' Next, inside the bash script I'm attempting to call an awk script and pass it these same values: echo echo | awk -v FIELDWIDTHS=$FIELDWIDTHS -v OFS=$OFS -v INPUTFILE=$INPUTFILE -v OUTPUTFILE=$OUTPUTFILE -f ~/bin/fixedWidthToDelimited.awk The awk script doesn't seem to be able to understand correctly what's being passed to it, I keep getting fatal errors. Can someone please help me understand how …

Member Avatar
Member Avatar
+0 forum 2

Hello! I am normally in the PHP / Web Development section of DaniWeb. It's a pleasure to finally have a reason to check out other sections of DaniWeb! So, I am logged in as root at the Command Line Interface over SSH - on Debian 7 Wheezy running on a BeagleBone Black Rev B6 - and I am running into an unexpected problem. I have made a folder ~/folder/pythonversion I go to ~/folder/ I type "ls -l python*/" I expect ls -l to match the "python" part, and match "version" to the * - therefore returning the pythonversion folder name …

Member Avatar
Member Avatar
+0 forum 4

I want to find common line in two files and replace the next line of first file with the next line of second file. (sed,awk,perl,bash any solution is welcomed ) Case Ignored. Multiple Occurrence of same line. File 1: hgacdavd sndm,ACNMSDC msgid "Rome" msgstr "" kgcksdcgfkdsb msgid "" hsdvchgsdvc msgstr "" dhshfjksdfhmd msgid "Vidya" msgstr "" sdjhcbnd dcndnv cfnkdndvrknvkf dfkvrnkdfnk snfvrkng msgid "Rome" msgstr "" wdbhkjbcfj #dmcdmf f,nvdf, fvnfnvk vfmf,mv vfn msgid "vid" msgstr "" dmcbdmbcvmfbvmkhsdk file 2: dfhkvgjbfrvkf msgid "Rome" msgstr "new bie" sdbsjbcdcbwoido fjcdcvnm msgid "vidya" msgstr "expert" dvnjfkdvhnkfvnknsbdjh msgid "vid" msgstr "newton" dfenfjdbrfjbvlfnvl dcnkncvkdfvknfv fcndkbvknfkv vfdnkvnfknbvkfn Later …

Member Avatar
Member Avatar
+0 forum 2

Month CBS GFS HR HR Payroll INCV cbs1 gfs1 hr1 hr2 hrm incv1 Baseline <=97 <=125 >=11 >=19 <=25 10 (6mths) 2013-07 97 89 14 28 30 4 2013-08 58 103 18 6 24 18 2013-09 54 110 11 14 25 17 2013-10 108 129 17 8 23 18 2013-11 52 137 12 8 21 30 2013-12 18 84 6 0 13 13 2014-01 8 6 1 0 9 3 #How to create a standard deviation based on the baseline for the 6 months AND after calculating the standard deviation, it will do a flag and prompt/inform the user that …

Member Avatar
+0 forum 0

I am trying to search for a shell script if it is running and then assigning the count to a variable. Let the script be ScriptXYZ.sh. I wrote: proc_count=$(/bin/ps -ef | grep ScriptXYZ.sh | grep -v grep | wc -l) The problem that I am facing is that even when there is no instance of the ScriptXYZ.sh running I get a proc_count = 2. I tried running the command directly in the terminal and it yielded zero. But this variable always fetches value 2. I tried to put the quotes around it. proc_count="$(/bin/ps -ef | grep ScriptXYZ.sh | grep -v …

Member Avatar
Member Avatar
+0 forum 3

I need a script that connects to a device on my network and export a list of data... #!/usr/local/bin/expect -f spawn telnet hostname expect -exact "Username:" send -- "username\r" expect -exact "Password:" send -- "password\r" expect "#" send -- "command\r" interact expect "#" send -- "logout\r"` I get some desired output but not completely. The output has more than 4000 lines and at line 80 the script gets a line " --More-- " waiting for user. How can I get the full output?

Member Avatar
Member Avatar
+0 forum 1

i've just given a script to update and maintain by my manager, but its bash and i dont know that much about it.. i currently have a script that looks through .txt files for given serials that then reports to a php webpage. within this script we have around 20 variables 1 for each testset labelled ts1 - ts20 most the testsets have a standard 7 digit serial that we look for and this is what is assigned to each variable..eg TS1=1234567 TS2=2345678 however i have one testset that has a unique serial because of the tests it carries out. …

Member Avatar
Member Avatar
+0 forum 2

I'm no pro when it comes to BASH, but I have been known to shell-script my way out of a problem here and there. One of the useful things you can do is a for-loop, whether it be used on file names, script arguments, or just a string of words. Here are some very basic examples on how to do for-loops in BASH. Edit: Fixed per Watael's suggestions.

Member Avatar
Member Avatar
+0 forum 1

I'm no pro when it comes to BASH, but I have been known to shell-script my way out of a problem here and there. One of the useful things you can do is a for-loop, whether it be used on file names, script arguments, or just a string of words. Here are some very basic examples on how to do for-loops in BASH.

Member Avatar
Member Avatar
+0 forum 3

This is another useful script I came across. It prints a color-code chart in your terminal. It can help you find the color-code you are looking for, or view the current color-scheme you are using (people use it on reddit/r/unixporn to show off their system's theme, I use it to grab color codes). I figure someone may get some use out of this, and there aren't many "Shell Scripting" code-snippets, so I'll put it here.

Member Avatar
+0 forum 0

I didn't write this, the credits are in the code. It's a code-golf version, and I'm sorry about that. I am trying to 'decode' it but I don't have the skills, so the 'decoded' version doesn't have the right colors. This is an example of what you can do with BASH, or possibly other shells, and it's just a neat thing to see. So I offer this up for your amusement, I've tested it and combed through it to make sure there's no hidden tricks. As far as I can tell it only uses a few commands like `echo`, `printf`, …

Member Avatar
+0 forum 0

Hi, I am trying to write a small shell script that will take user input on SVN branch and validate that the requested branch exists in SVN. And then continue with other operations if the branch is valid. I tried the following but seems its not working right: VALID_BRANCHES="4.2.1 4.1.0 4.3.1 4.2.2" for brnache in $VALID_BRANCHES do echo "Checking if $brnache is a valid branch in SVN" if [ "$1" != "$brnache" ]; then echo "it isn't" continue else echo "$1 is a valid branch" break fi done

Member Avatar
Member Avatar
+0 forum 3

i am a beginner. i need online tutorial for shell scripting. there are many on the web.. which one to choose??

Member Avatar
Member Avatar
+0 forum 2

I have a bash script that executes @ init level 3. I would like to "wrap" (for lack of better word) this bash script in a php script. Use the power of php to supress any output from the bash. Also display only the splash logos (like what you see when Windows is loading for example). Any questions? i am waiting for them?

Member Avatar
Member Avatar
+0 forum 3

I have to write two scripts, one in bash and one in dos. My dos one works perfectly but I'm having trouble with my bash one. The assignment is to make a script that takes a command line argument (from a test script) and return the change. So if the number is 94, the script will say There are 3 quarters. there are 1 dimes. There are 1 nickels There are 4 pennies. if the number is 25 it will say that is 1 quarter. if the initial number is 0, give a message saying there is 0 cents entered. …

Member Avatar
Member Avatar
+0 forum 2

Hello everyone, i am fairly new to shell scripting so please bear with me. The following script is supposed to read words from a file and depending on the word print different things. However it always prints the default value. It also refuses to work completely if the first line in 'numbers.txt' is not a blank line. I would be grateful for any hints whatsoever. script #!/bin/bash file="numbers.txt" while read line do operator=`awk '{print $1}' $line` case $operator in "divide") echo "/";; "multiply") echo "x";; "add") echo "+";; "subtract") echo "-";; *) echo "default";; esac done < "$file" numbers.txt (the …

Member Avatar
Member Avatar
+0 forum 5

So Im using our university servers through an ssh connection. I have a bunch of files in a directory which I would like to run through a perl script. So I thought this simple script I concocted should do the trick. I have used similar script on my home computer to do renaming of files (replace last line with mv $file $newfile) and it worked all-right. Alas when I use this on our uni server. Then it will produce error message : ./super: line 4: syntax error near unexpected token `newfile=`echo $file | sed 's/ehed/ehedp/'`' Is it something to do …

Member Avatar
Member Avatar
+0 forum 1

I'm almost done with college and I want to work on a side project that I could use to show case my skills. I'm looking for something that I can combine a bunch of different aspect into one. I know this will be a big project and won't be able to do all at once, but I want something that I can combine linux/bash, database (postgres/mysql), php, sysadmin skill sets, and maybe c++/networking. Any ideas would be greatly appreciated. Sincerely yours; jdm

Member Avatar
+0 forum 0

I have a bash script (test.sh) which reads parameters from the command line. The parameters could look like this: param1 param2 param3&ext param4 param5 The problem is that when the script reads the parameters and then echo them I get the following: param1 param2 param3 No command 'ext' found did you mean: <different commands from different packages> ext: command not found [1]+ Done ./test.sh param1 param2 param3 I want the output to look like this: param1 param2 param3&ext param4 param5 The source code of my script is: #!/bin/bash # # test script # echo $1 echo $2 echo $3 echo …

Member Avatar
Member Avatar
+0 forum 9

The End.