A shell script is a script written for the shell, or command line interpreter, of an operating system.

learn more… | top users | synonyms (1)

1
vote
2answers
29 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 ...
1
vote
2answers
37 views

How to find files by the time in their filename?

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
32 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
55 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
29 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
44 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 ...
1
vote
2answers
65 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
1answer
45 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
27 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
63 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
42 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
42 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
33 views

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

when i run 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 $USER@$SERVER ...
0
votes
2answers
60 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
63 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 ( ...
9
votes
3answers
132 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
35 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
80 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 ...
2
votes
1answer
41 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
36 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> || ...
-2
votes
1answer
45 views

I am new to bash shell scripting on Linux/Unix. Can anyone please give me some practical examples to start with [closed]

By some practical examples, i mean such examples which make my daily administration tasks very easy. Mostly i need backup of the files from a current directory, sending files to an FTP server, and ...
1
vote
1answer
33 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
65 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
73 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
55 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
62 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
56 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
209 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
46 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
41 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
35 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 ...
3
votes
1answer
63 views

ls gives me different sort orders during a cron job

I have a cron job that, among other things, does a recursive ls of a directory into a file. This gets compared to another file that I've created that, supposedly, contains an identical listing of the ...
3
votes
3answers
55 views

Editing config file via a bash script

I've been trying to write a simple bash script which I'll be using to install an application and update it's config file. I'm having hard time to have get it's config file modified. # ...
2
votes
1answer
44 views

How to check if a currently running process is opened by root or user

I'm currently creating a BASH script to kill off processes. I first check if the process is running then kill it. But I would like to add a nested if to find out if that process was opened by root ...
4
votes
1answer
70 views

output while reading keyboard input

I'm trying to write a script that will ssh into a box, start a processes that needs to be monitored (by a human) for success or failure then move onto the next box and repeat. I've been trying to use ...
0
votes
3answers
34 views

using find, exec, sed to manipulate strings as args to another program

I can use find like this find -type f -path "./src*" -name "*.php" to find a list of files. For example ./src/Superuseradmin/Model/Mapper/UUID.php What I need to do is manipulate each string in the ...
3
votes
3answers
166 views

How to remove any string from a file via shell scripts?

I try to remove string from .bash_profile. String is added when my shell script run: My string at bash_profile as follows: # for Myapllication export MYAPP_HOME=/opt/myapp I want to remove the ...
0
votes
1answer
60 views

Unexpected whitespace using sqsh in command substitution [closed]

Below shell script instruction behave in weird way ARG_DATE=`sqsh -S $SERVER -U $DB_USER -P $DB_PASSWORD -D dbname -h<<END SET NOCOUNT ON go select convert(varchar, PRIOR_COB_DATE, 112) from ...
0
votes
4answers
78 views

echo a loop with variables command

I have several lists and want to run some commands over them. As lists are long I want to run those commands parallel to each other, hence using nohup. For every item I tried to echo a loop that ...
-1
votes
2answers
80 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 ...
2
votes
2answers
81 views

How to compile a selection of Markdown documents using a shell script

Technical authors are increasingly being encouraged to write in standalone topics. Topics are written so that they make sense when compiled into different packages or when they are read in ...
1
vote
1answer
99 views

Comparing file times in ksh

I have developed a script which will compare two dates. #!/bin/ksh #################################################################### # #DECLARING ALL THE VALUES AND PATHS # ...
1
vote
4answers
134 views

Log in to multiple remote servers and execute a script [duplicate]

I want to make a script that will remote login to the multiple servers listed in a txt file like 10.3.9.6 10.3.9.7 and all servers have same username and password. and want to capture the output of ...
-2
votes
0answers
42 views

Outfile has a strange name [closed]

I ran a shell-script full of awk commands like this: awk 'do something; print "bananas"' infile >> outfile (in fact there where two files running at the same time, if that matters) the ...
5
votes
1answer
39 views

What do you use the -t “tag” option for in logger?

When using the "logger" command to write messages to the system logs from scripts, I use the -t "tag" to store the scripts name along side the message it's written to the log. I do this to make ...
3
votes
3answers
75 views

Portable way to get script's absolute path?

What is a portable way for a (zsh) script to determine its absolute path? On Linux I use something like mypath=$(readlink -f $0) ...but this is not portable. (E.g., readlink on darwin does not ...
5
votes
3answers
212 views

Walking through files in directory randomly

How to change for track in *.mp3; do so that all .mp3 files in the current directory are walked through but in a random way?
3
votes
1answer
63 views

Can't indent heredoc to match nesting's indent

If there's a "First World Problems" for scripting, this would be it. Mainly asking because I feel like I should know how to get around it if I need to. I have the following code in a script I'm ...
1
vote
1answer
54 views

get free string genre id3-tag and not only genre number in bash script

I'd like to read the id3-genre tag within a bash script. I tried id3tool, eyeD3, etc -- but these tools just support the genre number. How to get the free string genre tag? My music players (Amarok, ...
0
votes
2answers
70 views

`ps | grep | kill` aborts my script prematurely [duplicate]

I have a Linux computer that I remotely SSH into using plink on a Windows XP machine. I have the Plink program set to execute commands in a script using automated login: plink -ssh [domain name] -l ...

1 2 3 4 5 18