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

learn more… | top users | synonyms (2)

4
votes
3answers
235 views

KSH - if/then/else vs. double amps (&&) and double pipes (||)

I am wondering what are the best practices regarding if/then/else ; I tend to use the following form (because I find it easier to read) #!/usr/bin/ksh # [[ -f /path/to/target/file ]] && { ...
1
vote
1answer
39 views

read input from user in while loop having input and output redirection

This is my code: while IFS=',' read a b c; do read input echo $input done 3<&0 < input.csv > output.txt I took care of input redirection by redirecting through pipeline. But ...
0
votes
2answers
73 views

How can I filter ping results by time?

How do I filter out any pings that are under a certain ms, ie, only echo ping responses above 500ms to the text file? IP=$1 SECONDS_Between_Pings=$2 ping -i $2 $1 | while read pong; do echo $(date) ...
1
vote
3answers
70 views

UNIX KSH/BASH Call by Reference using Array (at GNU bash 4.2)

I am new to Unix shell scripting My code is as follows: i=0 for var in 'a' 'b' 'c' 'd' 'e' do content[i]=var ((i=`expr i+1`)) done a=10 b=50 c=40 d=90 e=100 Now I wanted to print the local ...
1
vote
2answers
57 views

Redirecting stdout and stderr of specific lines

I am reading a file and redirecting the entire output to a file. I would like to redirect stdout and stderr of certain expressions to screen as shown below (just an example): #!/bin/bash OLDIFS=$IFS ...
3
votes
3answers
53 views

Traverse, copy & transform file names

My issue: I need to copy log files, all with identical names, but stored 1-deep in subdirectories, and change their names. I'm copying from the a folder called Logfiles which contains a bunch of ...
0
votes
0answers
37 views

shell calling another shell program fails when run by crontab

I have scheduled to run the run.sh program like this: 16 09 07 * * root /opt/db_maintain/run.sh > /opt/db_maintain/temp-log and here is the run.sh: #/bin/bash #********* Saman ********* ...
2
votes
1answer
90 views

About executing shell script

Suppose I have a shell script file foo.sh. I can do chmod + x foo.sh and change it into an executable file. In Kernighan-Pike: Unix Programming Environment (UP) they show that after this typing ...
-1
votes
1answer
53 views

Generate a tarball or (.tar.gz) of the recently modified files in the directory

As the title says, I need help creating a linux script that generates a tarball or (.tar.gz) of all the files in the directory passed in as an argument to the script and have been modified in the past ...
2
votes
2answers
72 views

Tool to generate TCP traffic

I want to generate a TCP traffic starting from the port 0 to the port 65535. 1 tcp packet for each port with 1ms between 2 packets. The generator should not care if there is a TCP ACK or not. Are ...
1
vote
1answer
52 views

KSH/bash for File Creation Dynamically

I am new to ksh and unix and I am learning it: I wanted the following:I have a directory name tmp on that directory on basis of FileName Category I wanted to create 'n' number of files dynamically. ...
2
votes
4answers
144 views

How do I extract the first integer from text string in a column of a tab-delimited file?

I work in Medical Genetics and often have delimited text files where in one column (ex. column 5) there is a text string with a "mutation" in our jargon: c.2458C>T or c.45_46delAA or ...
0
votes
2answers
54 views

Check whether text contains non-ASCII characters in a shell script

I have a file, I want to determine if it contains only English ASCII characters. I thought this is a very common question, but when I googled it, there is no direct answer or related. According to ...
0
votes
1answer
44 views

How to change bash script output when the script is running?

I have the following loop which counts from 0 till 99: #!/bin/bash for ((i=0;i<100;i++)); do echo $i sleep 1 done Is there a way to change the result of the output from terminal while ...
17
votes
2answers
2k views

How did this '&' at the end of my command, make the script SO fast?

While solving some CTF challenges online, I came across a situation where I needed to bruteforce a server. This is the code I wrote: #!/bin/bash for i in {0..9}{0..9}{0..9}{0..9} do echo ...
3
votes
1answer
45 views

automate the process of fixing all broken links

There are lots of broken links in my system. I wrote a script to relink all broken links. But, after the scripts runs, find would again show me that the links still exists. This is my code: find ...
2
votes
2answers
179 views

how to check if both parameters are set in bash? [closed]

Say I have a executable bash file script.sh. I want to use it as ./script.sh p1 p2 p1 and p2 are two necessary parameters for this command. If either one of them is missing, the command should ...
2
votes
1answer
57 views

Using find and sed to copy 20th line of many files into one file

I have a folder called "PKA1" Within this folder I have several folders that look as: 1eV, 2eV .... 30eV Within each of these I have subfolders I have a file called PKA.dump I want to copy the ...
0
votes
2answers
78 views

Recursively remove files with idx > 10,000

The problem In the current working directory I have several (very many) folders and some of them have lots (like 100,000+) of files inside. My goal is getting just the folder with 10,000+ files and ...
1
vote
2answers
72 views

Debian: umount /media/usb0: “Operation not permitted”

I recently moved from Ubuntu 14.10 to Debian Testing. Under Ubuntu I had a shell script for backing up my home folder to a USB stick. The last line of the script unmounts the USB stick. Adapting it to ...
4
votes
2answers
142 views

Increment a variable using a Bash script

I have a file that contains the following text. // // test_file.h // test project // // Created by Test User // #ifndef test_file_constants_h #define test_file_constants_h // Generic includes ...
-1
votes
0answers
13 views

Process2 not taking control over process1

I have a device which has two cli consoles.One console say Xwhich comes by default when device comes up. My task is to start another console say Ybased on a condition say if variable has value=start2 ...
2
votes
4answers
125 views

How can I find the program I'm hiding in bash

Say I have PATH="home/bob/bin:/usr/bin". I am writing a bash script /home/bob/bin/foo that will do some munging and then call /usr/bin/foo. Of course I want to be able to use this script on ...
1
vote
2answers
56 views

sed - doesn't append new line EOF and replaces letter not defined

I am experiencing a strange behavior using a sed command (got to be sed, no awk in this case) and got two questions for you, hoping someone got the skills to explain me what I am doing wrong. I want ...
1
vote
2answers
54 views

Splitting the working directory in a bash script

If a do: IFS="/" read -ra PARTS And type in a path manually, it creates the array "PARTS" as hoped, however: IFS="/" read -ra PARTS <<< $(pwd) creates an array with a single element, ...
3
votes
3answers
164 views

Variable not expanding inside another variable bash

I am reading a csv file in bash script as follows: resource='/data/bscs/' while IFS='|'read seqid fname fpath do echo "FILENO: $seqid" echo "FILENAME: $fname" echo ...
1
vote
1answer
61 views

Unix Shell : Array assignment not working [duplicate]

I am new to unix shell I am learning array by following code source_array_list[0]="a" source_array_list[1]="a" source_array_list[2]="a" source_array_list[3]="a" source_array_list[4]="a" ...
1
vote
1answer
46 views

Unable to track error

I am new to Unix shell scripting, While running my program I found the following errors today.ksh[36]: test: 0403-004 Specify a parameter with this command. sed: 0602-419 Cannot find or open file ...
0
votes
1answer
44 views

Error while passing variables for keyword match using sed

I am a beginner in scripting. I am writing a bash script for text processing where this command is giving me error: sed -e "/\<$7\>/ /\<$5\>/$6/" < "$2/$1" > "file.tmp" This is ...
-1
votes
0answers
28 views

Can we connect Winscp using power broker?

I am connecting through power broker i.e pbrun command via putty to server. Can someone guide me, How can I connect to the server if I am using WinSCP because authentication will be done only I ...
1
vote
2answers
33 views

Script to do periodic printing

I have a networked inkjet printer (HP all-in-one photosmart 5510), and currently I have a simple script that reminds me periodically to send a small job for printer so that the ink doesn't dry up. I'm ...
3
votes
3answers
115 views

Bash : Native way to get rid of quotation around each array member

I read an array from another script. This array needs to put " " around all array members since some members are empty. in_file=./data vector=($(./readdata.sh 0 $in_file)) for index in ${!vector[@]} ...
1
vote
3answers
46 views

how to execute commands on remote server as different user

I am trying to connect to server B from server A using ssh and executing commands using some other user. However, when I try searching for a pattern in log file it says "cannot open log file" below is ...
1
vote
2answers
40 views

Bash script strange behavior with echo - printf in a file

I want to print part of the content of a .csv file in another file if there is a match with some condition: The csv content is like this abc test;ABCtest.it xyz test;XYZtest.com I read the content ...
1
vote
1answer
58 views

How can I skip empty files with sed?

I am using sed like this: sed -e 's/ *| */|/g' ${array_export_files[$loopcount]}>>$TEMPDIR/"export_file"_${testid}_${loopcount}_$$ under a while loop but problems come when the file is ...
0
votes
1answer
62 views

Expect Scripts - Reading from Files and Accepting User Input

How can I write an "Expect" script to: 1) iterate over a list of IP addresses and log in to each to perform commands (like in a BASH for loop). Right now I just copy/pasted the few lines that are my ...
1
vote
1answer
34 views

Match closest equal or preceding timestamp

I have a series of timestamps representing events, e.g.: 20150401_1120 // event a 20150401_1211 // event b And a series of logfiles, each representing a fixed period of time and timestamped ...
0
votes
2answers
25 views

Dividing up columns and submitting the value as stdin into a seperate program within a script [closed]

I currently have two programs written in C named "remove" and "calculate". When I call ./remove it removes some data from stdin. When I call ./calculate which takes in an argument and also data from ...
2
votes
2answers
39 views

Is it possible to change the PS1 periodically by a script in the background?

I just came across the PS1 variable (so I am far from being an expert). It is possible to change the prompt by simply changing this variables value, for instance: PS1="\h" hostname as Prompt PS1="\j" ...
0
votes
1answer
38 views

Want material to teach Unix basics [closed]

HP-UX ** B.11.31 U ia64 ** unlimited-user license Hi, I have been working as a script (korn and bash)developer on Unix platforms for 3+ years. I have to train a team on Unix. And although I know a few ...
2
votes
1answer
26 views

cat to stderr while reading to end of file marker

Leaving aside the question of whether usage output should go to stderr or not, if you had to redirect the output of the cat command below to stderr, how would you do it? function usage { cat ...
0
votes
1answer
37 views

How to set path in cronscript

I am running a cronscript like: */45 * * * * /path/to/php /path/to/file.php it creates a file and put on home directory; But I want to create this file in my desired path like: */45 * * * * ...
1
vote
2answers
52 views

Script to hang up Asterisk channels

I am trying to create a script for Asterisk. We use a lot of channspy. Sometimes the channspy stays opened and didn't hangup even if the softphone is hangup (I don't understand why). So I thought of ...
0
votes
1answer
45 views

Modify part of line if keyword is found using sed? [duplicate]

I want to modify a line if a specific keyword is found in a line. CS_CODE, SM_NUM, PORT_NUM, DEV_PORT_NUM, DIRNUM, MAIN_DIRNUM, BILL_NO, ADR_NAME In above line, if 'PORT_NUM' is present then ...
0
votes
1answer
41 views

List files with memory space older than 14 days

In shell scripting how to find 14 days older than files and directory in a account I need to list them with their memory space ex: 0 ./.vxz.tmp 658 ./.zshrc 6 ./dummy.txt 2.1K ./ss1s: 489K ...
0
votes
1answer
40 views

Moving multiple files from one folder to another and rename them [closed]

I have a list of current file names and Original file names in a text file. The current name and the original name are seperated by a Tab or hypen. I want to move the file with the current file name ...
2
votes
2answers
40 views

grep with count of individual patterns

I have a file with MAC addresses (1/line with : as separator, sorted) and I need to find out how many times each of these MAC addresses appears in the file. I modified this: How to count occurrences ...
3
votes
1answer
24 views

Set the affinity of a process from a shell script as it is being launched

I have a script (.sh) where I launch applications like this #!/bin/sh ./application1 configuration1.cfg param1 param2 param3 & sleep 2 ./application2 configuration2.cfg param1 param2 param3 ...
0
votes
1answer
65 views

How can I translate in the CLI an English word into a German one?

I want to write a Script that picks a random English word from /usr/share/dict/words, translates it into German, display both of them for a certain amount of time and repeat the process. I only know ...
1
vote
3answers
60 views

copying files to other location

I have multiple directories named such as: 15mar20a_00021sq_v01_00019en.frames 15mar20a_00021sq_v01_00020en.frames and so on... each contains 7 files having an extension of .raw. Examples of the ...