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

learn more… | top users | synonyms (1)

2
votes
2answers
297 views

Having multi lines in bash command substitution

I have a very long bash command inside a command substitution like following: $( comaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaand ) I want to know if there is a way to break this command into shorter ...
1
vote
2answers
101 views

enf of file unexpected (excepting “f$ing ”fi")

os: pfSense (nanobsd) shell: csh script: /etc/rc.conf_mount_rw mount -t msdosfs /dev/da0s1 /mnt/usb if ( -s /var/squid/log/access.log ) then cat /var/squid/log/access.log | perl -p -e ...
1
vote
2answers
2k views

How to return the exit code? Error: return: Reading: numeric argument required

Here's a simplified version of my script. My question is, How do I return the exit code from apt-get in this case? #!/bin/bash install_auto() { apt-get -h > /dev/null 2>&1 if [ $? -eq 0 ] ; ...
2
votes
4answers
1k views

List of servers to check for SSH availability

I have a list of IP address that I need to SSH to and log if I could get to them. I would use a Ping script, but DNS might have already reassigned the address. I do not care about the ones I can't get ...
-1
votes
1answer
91 views

Script to take username and password [closed]

I need to stop few services. whenever we entred the command to stop the service it'll prompt for username and password. We need to automate this whole scenario to take username and password directly ...
1
vote
3answers
512 views

Split long output into two columns

Is there a simple utility or script to columnate the output from one of my scripts? I have data in some form: A aldkhasdfljhaf B klajsdfhalsdfh C salkjsdjkladdag D lseuiorlhisnflkc E sdjklfhnslkdfhn ...
1
vote
3answers
297 views

Renaming or making filenames unique

I have written a plsql procedure using utl file to create files in the temp directory in Unix. I am sending the names of the files to a shell script to mail these files and delete after mailing from ...
1
vote
2answers
555 views

Trouble with read line script in Cygwin

I'm on windows 7 using Cygwin. My script and text file are located in the same directory. #!/bin/bash while read name; do echo "Name read from file - $name" done < /home/Matt/servers.txt I get ...
1
vote
0answers
57 views

how to list blocked connections events by the firewall?

So, I used firestarter that had logged blocked connections events with some useful details (but it is not being updated and I found somewhat unsafe as any moment we could click to deactivate the ...
2
votes
2answers
913 views

Find the process id of a java application in a bash script (to see if the target application is already running)

I know there are a million questions on getting the process ID, but this one seems to be unique. Google has not given me the answer, so I hope stackexhange will help rather than close this question. ...
0
votes
1answer
50 views

Test for files containing certain numbers on its names

Suppose that the folder $folder contains the files 2012-01,...,2012-N1,2013-01,...,2013-N2 and so on. I'd like my script to ask for a natural number M and: if the files 20M-* exist then ask for ...
4
votes
3answers
714 views

Preventing propagation of SIGINT to Parent Process

Considering a scenario where a Parent program (could be a C++ program or a Shell Script) executes a Child shell script, when we hit Control+C (or whatever character is configured to be the INTR ...
1
vote
1answer
123 views

Udev: running a shellscript that accesses an X display [duplicate]

After getting my 3g-modem to work in Arch Linux I wanted to eliminate some manual labour required in the process. Hence I needed to create an udev rule. After some trial and error I came up with the ...
5
votes
3answers
173 views

${#array} vs ${#array[@]}

As far as I can tell both ${#array[@]} and ${#array} evaluate to the number of elements in $array. Is there any reason for preferring the longer form (${#array[@]})?
5
votes
2answers
110 views

Is there a less convoluted way to set the $path array locally within function?

Is there a less laborious way for setting a local version of the $path array than what's shown in the following snippet? foo () { local holdpath holdpath=($path) local path ...
2
votes
2answers
2k views

How to run sudo commands remotely via ssh -t?

I have a script that logs into a remote host via ssh -t and uses sudo service foo restart. The requirement is to avoid the prompt for a password on the remote host. The remote host authenticates via ...
2
votes
1answer
375 views

Use the terminal's autocomplete path feature for input to a shell script

I want to make a script that: (1) Gets a path giving the user the ability to use tab to autocomplete, then (2) gets a filename from the user, and then (3) creates a file at that path with extension ...
2
votes
2answers
105 views

ksh + delete number from string

the string IP include some IP address numbers as the following example echo ${IP[*]} 192.9.200.1 192.9.200.2 192.9.200.3 is it possible to remove some IP address number from the list ( using ksh ...
2
votes
2answers
110 views

Is tty_nr referenced anywhere else in GNU/Linux procfs?

This is a problem I've been trying to solve on my own for some time without any luck. I'm trying to write a script that (amongst other things) can take an arbitrary PID and map it to TTY device's path ...
1
vote
2answers
867 views

ssh to multiple hosts and run a command [duplicate]

How do I ssh into multiple hosts (e.g host1, host2, host3, etc) and cat /etc/fstab to generate report.txt?
1
vote
2answers
155 views

perl one liner + how to match IP address that located in the first/sec field of file

the following perl one liner syntax verify if IP address in "$IP" match the IP ADDRESS in file perl -ne 'BEGIN{$IP=shift} print if /(^|\s)\Q$IP\E(\s|$)/;' $IP file file have two fields as the ...
2
votes
2answers
576 views

How to find files by the time in their filename? [duplicate]

We have a directory contains files which contains time in their filename ./test.2013-06-11_06-01.gz ./test.2013-06-12_01-01.gz ./test.2013-06-13_03-01.gz ./test.2013-06-14_03-01.gz ...
3
votes
2answers
96 views

Cron job for every minute executing out of order?

I'm setting up some shell scripting to be executed every five minutes, then every minute on our client's system, to poll a log and pull some timing information to be stored and accessed by another ...
4
votes
3answers
462 views

Reading a binary file as an array of bytes or 16 or 32 bits using shell script

I am working on ARM-based modem Linux host machine and I need to read a bin file as an 8-,16- or 32- bits array. I basically need to encrypt the file in question and was thinking of just XOR-ing the ...
0
votes
1answer
413 views

Why is my shell script hanging on `apt-get -y upgrade`?

Ubuntu : sudo DEBIAN_FRONTEND=noninteractive apt-get -y update sudo DEBIAN_FRONTEND=noninteractive apt-get -y upgrade sudo reboot Script is always interrupted after upgrade and then it will stay on ...
1
vote
2answers
939 views

Create .tar.gz from a directory omitting some subdirectories and add only new or changed files

I need to create a script, maybe bash, maybe just a .sh that checks for files changes on a root directory and sub-directories of the root, and adds to a new file. The tar.gz file name should have the ...
2
votes
2answers
137 views

Directories are listed twice

I have something odd. I creates some directories using a very simple script : ... create all directories ( running under a user that has the correct rights ) e.g : mkdir -p ...
1
vote
2answers
259 views

Augeas in shell script

I'm trying to use augtool in shell script ex: #!/bin/bash augtool <<-EOF print /augeas/load EOF However if I execute this script, the script will run indefinitely with no output and the CPU ...
0
votes
1answer
31 views

how to display I/O file on shell [closed]

I am writing shell script and I need to display my output at the same time however it doesn't work with 2> somefile.txt and if I do | tee -a somefilel it will not overwrite which I need to . <> ...
4
votes
3answers
1k views

Terminating a bash shell script running in the background

I often use bash shell scripts to run simple commands for many different files. For example, suppose that I have the following bash shell script, called script.sh, that runs the program/command foo ...
1
vote
1answer
105 views

Why do I get different outputs when running my shellscript manually from when I run it with cron? [duplicate]

I have a fairly simple shell script (foo.sh) that looks like this: #!/bin/bash echo -n "$USER,$(date)," `binary -flags | sed -e '1,30d'`; exit 0; This script is supposed to prepare some output ...
0
votes
1answer
161 views

MAC bash commands stop working properly

I was trying to install some stuff for scala development on my MAC, and probably I managed broke the shell/terminal while I was mindlessly running some scripts that I don't know. Now when I start the ...
3
votes
1answer
422 views

Noninteractive script running over ssh is interrupted as apt-get finishes

When I run the following non interactive script on Ubuntu Server 13.04 it's interrupted when lxc-docker package finishes installation. Script : ssh -o StrictHostKeychecking=no -t -t -i $CERT ...
0
votes
2answers
206 views

search fitting ipv6 address for MAC-Address in neighbours

I have a list of possible to ip6 addresses converted MAC-addresses, that could be found in the output of ping6 ff02::1%wlan0 possible mac addresses are for example: 66:70:02:75:80:fe, ...
4
votes
4answers
110 views

How to deal with spaces in a variable

I'm working on some scripting: for x in `find ./ -name *.pdf` do echo pathname $x done My filenames are Test1 ( Volume II), Test2 ( Volume II). I'm getting a return of pathname Test1 pathname ( ...
12
votes
3answers
293 views

When to use redirection to stderr in shell scripts

I know that well-behaved utilities like grep output "normal" messages to stdout, and error messages to stderr. $ grep '^foo' file1 file2 file1:foo grep: file2: No such file or directory When I'm ...
2
votes
1answer
95 views

issue with how newly made gnome launchers work vs launchers rebuilt after a system boot. (title change for clarity)

This isnt so much a request for help as a curiosity of mine. I wrote this script to quickly pop up four terminal sessions and fill my screen, since so many of my current systems have things that come ...
2
votes
1answer
199 views

How to open and work with terminals using bash script?

I need to open four terminals each will then connect to four different remote pcs and open specific directory locations on those pcs. Each terminal will be opened in different locations on my pc's ...
5
votes
2answers
349 views

How can I fix this SSH hostname tab completion script?

I found the following script (for bash) that enables me to get tab completion for any hostname I've connected to (from ~/.ssh/known_hosts): complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ...
2
votes
1answer
103 views

Is there a text-only equivalent (no curses) of `zenity --question`?

For my mercurial commit hook, I want to run my test cases and be asked whether I really want to commit if any of the tests fail. I'm thinking something like <run-the-tests> || ...
1
vote
1answer
104 views

Prompt user for sentence and store it without being disturbed by spaces

I have a bash function that prompts user to input certain data. I tried it with first name, last name, birthday etc. Data that is mostly represented in one sentence. When I ask for street + no. the ...
-2
votes
2answers
960 views

Loop over multiple addresses: ping and drop data into file

I would like to be able to have a script that will: look at a list of IP addresses Ping one of the addresses Take the data and drop it in to a file Move on to the next IP So far I have: cd ...
2
votes
2answers
2k views

Bash scripting - loop until return value is 0

I need to umount something in my script, but sometimes it unmount's before all of the data has finished being copied and causes the umount to fail. I looked for a way to do a "blocking" umount, but I ...
2
votes
1answer
1k views

Ssh to a box, run a command, output data to a file, then move on to the next IP adress [duplicate]

I want to run a script from my Jump server, have it SSH to a server, then run a command (like rm <file>, top or ls -lsa) then take that output and put it in to a file on my Jump server then move ...
0
votes
4answers
474 views

How to do a “if not” in Bash without a test?

I would like to use the return value of a bash function in a 'if not' statement. The following is an example script: #!/bin/bash function myfunction () { if [ $1 = "one" ]; then return 1 elif [ ...
4
votes
3answers
123 views

Back up logs to a new directory

I need help to write a script to copy log files. There are two format of logs: System_<date_timestamp>.log trace_<date_timestamp>.log New files are generated when trace log reaches ...
3
votes
2answers
333 views

How can I determine if HTML5 player is running in browser?

I would like to find a command-line or a script that will show me if HTML5 player is running or not in a browser (firefox or chromium). For example, to determine if Flash player is running in a ...
0
votes
2answers
158 views

EOF blocks my script?

I have this script (it is actually a snippet from a bigger script). #!/bin/sh if [ $actualsize -ge $MAXSIZE ]; then read dummy FILEPOINT <<EOF `dd if=myfile skip=8001 count=1 bs=1|od -x` ...
0
votes
2answers
458 views

Need to get the latest file with date timestamp for each month

I am just starting with Unix programming and I have a requirement. I have four files which are placed in my landing zone and I need the scheduler to pick up the latest file of that month and year. ...
0
votes
1answer
101 views

set command with — flag

I have a file (called text) that contains two fields of strings (separated by space) like what follows: 1.2.3 version1 When I use set command as follows, I have the first field in the $1 and the ...