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

learn more… | top users | synonyms (2)

1
vote
2answers
17 views

Timeout with 'service network restart'

I have a script running on fedora 22 where I am restarting service network as part of a troubleshoot calling service network restart. I want to check if that command is taking too long to execute. If ...
1
vote
2answers
38 views

Help me please to find my misunderstanding about this little piece of shell script

Actually, I have a folder which contains several sub folders with lots of images in each. I am trying to gather all the names of the files in each sub folder in a text file (filesNames.txt) in that ...
-2
votes
1answer
19 views

bash shell while loop is going beyond the conditional expression [on hold]

In my problem, it appears like j value and i value reach 6; where i should only run up to 5. Can someone please explain ? i=0; j=0; echo "values of $i and $j" > debug.txt; while [ $j -le 5 ] do ...
0
votes
1answer
36 views

Script execution failed

I have created a script to capture the heap and thread dump of a running java process. #! /bin/bash myhost=$(uname) if [ "${myhost}" == "SunOS" ]; then ...
0
votes
0answers
27 views

How to do multi threading using mkfifo?

I have a file which having milions of records like below. 8350000014|1234567|NULL|NULL 7336004920|478637|NULL|NULL 9876006473|478632|NULL|NULL 6730000012|1234567|NULL|NULL ...
0
votes
1answer
38 views

Validate user response in shell script

My shell script is working fine and the files are copying to the remote directory. However I need to check if my INPUT_STRING is starting with S and also check if the files are present in the ...
1
vote
3answers
105 views

Separating variable names from output strings with no whitespace

I have the following snippet of code where I intend to: Iterate 5 times the loop; get a line from a file (each iteration I need the next line fetched); use the line as a title for a file; put a ...
1
vote
0answers
18 views

American Fuzzy Lop run test program as unprivileged user or in chroot

I'm attempting to test tcsh on OS X with American Fuzzy Lop as an exercise, but don't want to accidentally clobber any useful files on my system. Knowing essentially nothing about fuzz testing, I did ...
0
votes
0answers
15 views

Unable to execute the rest of my shell script after installing Oh My Zsh [on hold]

I thought that here it will be better to ask for help with my problem. In a nutshell: I'm creating my custom shell script to simply customise my Mac. To make a short example: 1) I install OMZ using ...
0
votes
1answer
28 views

small error but seems annoying [duplicate]

I have error (command not found). I am newbie here. so what is the easy solution and explanation for this error?
-3
votes
1answer
38 views

recursive script not working

I am trying to add recursive support to my filegrep script. For some reason this does not work as expected: RECURSIVE_MODE=off # iterate over args for ARG in "$@" do if [ -d "$ARG" ] && ...
3
votes
2answers
53 views

How can I parse an ini file whose values may contain certain characters?

I have looked at a couple bash ini parsing scripts and I've seen this one used a few times here so I'm trying to see if it will work for me. It looks like it reads the ini file line by line multiple ...
1
vote
1answer
25 views

bash script trap for exit and err and logic for difference

I have a bash script and would like to add in the ability to trap for both EXIT and ERR conditions. The structure is currently trap cleanup EXIT function notify(reason) {} function build {} function ...
-1
votes
2answers
34 views

Need help with script for regular expression in bash

Using bash shell I have a regular expression which works fine on data. How do I write that regular expression to segregate data into 3 different cols in bash shell script ? Here is the Regexpression ...
0
votes
1answer
33 views

Run Concurrent Instances of a Command Inside a Shell Script

Let me start this by saying that I'm still learning bash scripting and I'm not aware of many things. If I miss something, feel free to scold me as you please. Onward, I'm creating a simple bash ...
0
votes
1answer
26 views

Bash script SFTPing into remote server and downloading files, cd into proper directory on local machine

I have a cron on my Ubuntu server that runs this bash script daily: #!/usr/bin/expect -f spawn sftp user@ip expect "password:" send "password\n" expect "sftp>" send "cd remote_directory\n" expect ...
-2
votes
2answers
43 views

find all jpg images from specific directory and copy it to other directory

How do I copy all the jpg images [files whose names end with .jpg] that exist in the directory /usr/share/backgrounds into to the jpg directory in /week/pictures/final/jpg then redirect any error ...
0
votes
0answers
19 views

Systematically change all visible color in multiple pngs via a script?

I have a large set of pngs to be used as icons for an application I am developing. The icons are all a single color and have a transparent background. Is there a systematic way to change the single ...
2
votes
3answers
48 views

Use a wildcard in directory path

I'm trying to write a bash script where part of a directory is a long, unknown string. I know the first part of the directory name. How do I combine the known string and the wildcard in the path? As ...
1
vote
1answer
31 views

Extract zip files into directory based on pattern of zip name

I have these zip files: PLP_633555_2015-03-04_01-12-01.zip PLP_634562_2004-03-02_02-15-07_UBIC.zip PLP_563462_2008-05-02_01-21-03_UBIC_STOC.zip And I need each zip extracted into its appropriate ...
2
votes
4answers
65 views

How to format a bash loop using sed, awk, grep, and wc

So I have a text file that I need to get extract specific lines out of and count the number of times a number in a specific column appears. I have about 100 or so of these files. I can get it done ...
0
votes
1answer
44 views

Why would this script work with bash on Kali, but not with bash on Xubuntu?

I have a script that I made when I was at home on a Kali virtual machine. It works perfectly there, but now I'm at work on my Xubuntu install and it's not working at all. The exact shell that I'm ...
3
votes
3answers
66 views

Replace a long string with the sed command: Argument list too long error

I'm trying to execute this command sed -i -e "s/BASE_64/$BASE_64/" FILE_NAME where $BASE_64 is a base 64 representation of a file content. sed gives me an error since the string is too long. ...
1
vote
4answers
53 views

How to gather the name of the files in each subdirectory into a text file in that subdirectory?

I wanted to save the names of all files in each sub directory into a text file in that sub directory, so I wrote this script: #!/bin/bash for X in "$PWD" * do if [ -d "$X" ]; then ...
0
votes
1answer
18 views

Why does the jobs command not work in shell script?

If I run jobs -l on command prompt it shows me the status of running jobs but if I run below file ./tmp.sh #! /bin/bash jobs -l It shows empty output. Why is that and how can I obtain information ...
0
votes
0answers
37 views

sed can't find file on a shell script [duplicate]

I've been running into a problem whenever I run the shell script containing a sed. If I try this argument by running the shell script with the following line, it gives me a bizarre error: arg=$1; ...
0
votes
1answer
58 views

inserting modified date into filename - 2 cases

I believe I'll ask two separate questions, but the context is the same, so I hope it's alright. I have an output of few processes as presented below (which I can't modify). 25978.csv 26044.csv ...
0
votes
1answer
57 views

How to write bash script while using command as condition in if statement?

I am writing a bash script to process input from html form. I have two issues which I can't seem to be able to figure out. I am a beginner to Unix. First problem is that I can't get my if statement ...
1
vote
3answers
93 views

How can I compare different files without opening them?

I have two directories A and B; each one contains a lot of sub-directories geom001, geom002 ....etc each sub-directory contains a file named results. I want to compare, without opening any of ...
0
votes
0answers
58 views

Start vino-server in Ubuntu 16.04 lts

I'm trying to raise vino-server in Ubuntu 16.04 but I could not. I am using this script and let me start by terminal: # /etc/init.d/vino-server.sh start but not as a cronjob: @reboot ...
2
votes
1answer
27 views

( test -n $st ) != ( test -z $st ) right?

As I read, test -n $string ==> Exit status is 0 if $string is not null, 1 otherwise and test -z $string ==> Exit status is 0 if $string is null, 1 otherwise But in this particular example, (I ...
1
vote
1answer
20 views

Question about if structure and loops

I am new in programing with bash script. Here is my problem: I am going to open a sort of data whose file name includes the date (format: file_yyyymmddhh.nc). There are some requirements: mm is ...
3
votes
2answers
50 views

Is there a reason to use “[ ! -f file ] || command” instead of “[ -f file ] && command”?

I found [ ! -f /etc/default/lxc-net ] || . /etc/default/lxc-net in /etc/default/lxc on Ubuntu 16.04 which seems to be replacing (my own or package maintainer code) [ -f /etc/default/lxc-net ] ...
0
votes
3answers
152 views

Where can I find the shell script for ls command? [on hold]

I am trying to understand how the ls command works, and I presume there is a shell script which defines ls somewhere in the filesystem. This correct? If so, where can I find it?
0
votes
0answers
38 views

Understanding bash script for getting drop down option

I have this script which reads the user input for executing some command, This is working fine. User=0 Path="/root/file/" Path1="/root/domain/samples/file" echo "Please select k1 l3 l8 o5 s2 s1 ...
2
votes
2answers
43 views

How can I more efficiently collect data from users on a vm?

I'm teaching a course this summer. My students' first assignment will be to install a virtual machine that I created (the machine will run Ubuntu). Upon installation they are to run the following ...
1
vote
1answer
47 views

How to enable CURL in UNIX server? [closed]

I have to make a web service call through CURL in shell script. For this, CURL should be enabled. Below is my server details: Sun Microsystems Inc. SunOS 5.10 Generic January 2005 below is ...
10
votes
1answer
138 views

Why do these bash fork bombs work differently and what is the significance of & in it?

I get how a normal fork bomb works, but I don't really understand why the & at the end of the common bash fork bomb is required and why these scripts behave differently: :(){ (:) | (:) }; : and ...
11
votes
1answer
519 views

Is there any way to tell if a shell script was killed with signal 9

I have a bash script (called from a java program) that keeps getting killed. I always catch the signal 15 with trap but then some other signal comes along that I suspect is signal 9 but am in ...
0
votes
1answer
42 views

Why this option not working in this Bash script?

I am expanding the following function to include the option -i | --ignore-case with error-handling #!/bin/sh [ $# -ne 1 ] && echo "1 argument is needed" && exit 1 find $HOME -type f ...
-1
votes
0answers
32 views

how to pass multiple column value in a command

I have a file oldnewmap.txt. This file has hundreds of records like the following, where column one represents oldnumber and column two represents newnumber. 21382,45678 34567,45663 44245,42455 ...
1
vote
1answer
19 views

linux periodic system check script or utility [duplicate]

Is there any commonly used shell script or utility to periodically check Linux file systems for changes, such as permission or ownership changes of configuration files. I am thinking of something ...
-1
votes
1answer
55 views

What's the meaning of this variable in Bash script?

So this is short script used to rename extension of files i found on tldp. #!/bin/bash Mysterious=65 case $# in 0|1) echo "Usage: `basename $0` old_file_extension new_file_extension" exit ...
1
vote
0answers
34 views

Changing permissions of the file, while using sftp command in a shell script

How can I change the permissions of the file/command, while using the sftp command via a shell script? My sftp connection is established, but it fails while executing the chmod command. As of now, I ...
1
vote
1answer
38 views

Get run time for two programs simultaneously

I am trying to make a shell script that could run tests on two differents programs simultaneously and compare their runtime in order to see which one has the best efficiency (tests have to be ...
83
votes
2answers
3k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
33
votes
2answers
250k views

Using 'sed' to find and replace [duplicate]

I know this question has probably been answered before. I have seen many threads about this in various places, but the answers are usually hard to extract for me. I am looking for help with an ...
59
votes
4answers
193k views

How to append multiple lines to a file with bash

I am writing a bash script to look for a file if it doesn't exist then create it and append this to it: Host localhost ForwardAgent yes So "line then new line 'tab' then text" I think its a ...
0
votes
1answer
3k views

IBM V7000 scripts for monitoring

Hello (I'm no hard core coder:), I try to develop a script to do some very basic monitoring on an IBM SVC. My goal is to get some information about the nodes and my quroum status and then send ...
8
votes
4answers
25k views

Recovered deleted files on Mac by command line

I accidentally deleted a file by running: rm -rf ./Desktop/myScript.sh I think it's possible to recover the file, because the rm command removes temporarily. How can I recover the deleted file on ...