A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

learn more… | top users | synonyms (1)

3
votes
5answers
171 views

How can I force a script to use more resources?

I'm running a very time-consuming script which takes many hours to end. Watching top I see that it's only taking 5% of the CPU at best, usually around 3%. Is there any way to force the script to use ...
1
vote
2answers
291 views

Bash shell scripting basic question regarding the syntax and basename

Consider the script below: myname=`basename $0`; for i in `ls -A` do if [ $i = $myname ] then echo "Sorry i won't rename myself" else newname=`echo $i |tr a-z A-Z` mv $i $newname fi done ...
5
votes
1answer
168 views

When is it important to write portable scripts?

Most code I write is in PHP. I have recently started learning shell scripting. Most of the resources and tutorials that I've come across are specific to Bash. Some warn about bashisms and some don't. ...
4
votes
3answers
115 views

shell script problem with using the operators

I am comparing two strings using the levenshtein distance algorithm. I got the PHP implementation of the algorithm from here. I am calling this php implementation from my shell script as below. ...
1
vote
0answers
34 views

Logging into multiple SSH servers as root and create an user with same power as root does [closed]

I need a script from which I can log into multiple servers as root (but not all root passwords are same;there are 3-4 different root passwords) and make a superuser (user with same access as root) but ...
6
votes
1answer
86 views

A shell-like environment for binary processing

This question came to me a couple of times before, now in response to the question Loop through binary data chunks from stdin in Bash Answers given in ...
2
votes
4answers
55 views

Wrapper command that runs program in temporary directory and deletes it after execution [duplicate]

I want to write a command that: takes another command as its arguments does a 'cd' to a temporary folder executes the command passed in the arguments removes the temporary folder afterwards ...
2
votes
5answers
149 views

Delete all files in directories except those whose path are listed in a file

Given the following files: data/A/a.txt data/B/b.pdf ... date/P/whatever.log ... data/Z/z.jpg I would like to delete all files in the data/A/, data/B/, ..., data/Z/ directories except those files ...
0
votes
0answers
56 views

replacement script multiple targets

I have this input file Name=code_229633_138;isoforms=1 Name=code_229633_138 Name=code_229633_138;Target=R77_09738T0 Name=code_230519_1;isoforms=1 ...
3
votes
7answers
688 views

Write a remote managing script

I need to be able to locally run a script that will connect to various servers and run commands on them. What is the best way to accomplish this?
0
votes
2answers
29 views

Help With Simple Script - Absolute, Relative Paths

I'm trying to execute a mono application, without requiring the user to type in 'mono filename'. It's just one line of code: mono ./Bin/jobshop.exe $1 $2 $3 $4 $5 $6 $7 $8 $9 It works great, so ...
1
vote
1answer
54 views

How do I rename lots of files on a directory without changing their extensions? [duplicate]

I have a problem! I have a bunch of image files with extensions. Jpg and. Png. I wrote a script that renames the files, changing their names in a pattern followed by a number like this: ... ...
2
votes
3answers
93 views

creation of user add

I'm having more then 59 servers I need to create a script for user add. purpose: if I'm creating a user in one server it will be reflected on all 59 servers. How can I accomplish this?
3
votes
3answers
342 views

if/then/else man page

I would like to know if there is any man page documenting the construction of the most basic script commands like if/then/else, while, for each, and all the relative switches, like -eq, -e, -ge, and ...
3
votes
3answers
249 views

How can I extract/parse a complete URL from a semi random string?

I'd like to have bash parse/extract a full URL (and only the url) from a random short string. Examples: bob, the address is http://www.google.com or https://foo.com/category/example.html is up ...
20
votes
2answers
534 views

How do I move all files output from a command?

I have this grep command to find files without the word Attachments in them. grep -L -- Attachments * I want to move all the files that are output from that command. How do I do that in bash? Do I ...
6
votes
2answers
191 views

What's the most efficient way to grep for two completely separate things and assign the values to separate variables?

CentOS 6.x I want to take the output from curl, grep for two completely separate strings, and assign their respective values as variables. What is the most efficient way to do this (without writing ...
1
vote
2answers
121 views

Creating a shell script that parses and redirects number into next command?

I am trying to create a script that kills an Xorg process. Here is an example of me running the commands in a terminal: First, I find the process id of the Xorg program (in this case, 2494): . ...
4
votes
4answers
496 views

Check for Process if Same is Running

Is there a script or a way in linux that when I try to execute a shell script/process, if the same is running, it will prompt that same is running and will exit otherwise it will continue.
2
votes
3answers
60 views

grab multiple lines after a matching target line

This question is similar to How to show lines after each grep match until other specific match? thus answers may be similar to those there. I am trying to grab and extract from a file the lines that ...
-2
votes
2answers
108 views

how to execute a python program in a shell script

I have a python program in that I wrote some python code (disk.py). I executed this program using the command python disk.py in a terminal, it worked. Now I want to execute it using a shell script.
0
votes
2answers
95 views

Using grep to find first two numbers of IP addresses?

I'm trying to figure out how to use grep to pull out only the first two numbers of an IP address in a list. I've got a routine that is isolating the log entires (from Exim) that I need, now I just ...
1
vote
3answers
141 views

What does “FILENAME=$(echo $INFILE | grep -oE ”[^/]+$“) ” mean?

FILENAME=$(echo /root/Source/code/script.sh | grep -oE "[^/]+$") I know that it would give me the file name from the file path here as script.sh. But can some one please explain me this?
1
vote
2answers
51 views

How to notice log file changes with Linux standard tools? [duplicate]

I need something that does not need to be installed. It's on an embedded system with very little space on the HD. I can't instal anything. I need to do it with something that is already included. I ...
3
votes
0answers
464 views

How do I reset a USB device using a script?

I have a USB GSM modem that does not always work property (Huawei E367u-2) Sometimes it gets reset (USB device disconnect/reconnect in logs) and when it comes back up, it has different ttyUSB numbers. ...
3
votes
3answers
129 views

Shell Script to move folders containing a specific word

I'm searching for an simple shell script to mv all folders in /var/www/uploads/ that containing Math or Physics in the name to /mnt/Backup/. I've never done something like that before, due to the ...
0
votes
1answer
33 views

Prompting when redirecting content of script to remote machine

I have simple script: #!/bin/bash while getopts ":u:" opt; do case $opt in u) USER="${OPTARG}" ;; \?) echo "Unknown flag has been used: -$OPTARG" >&2 exit 1 ...
5
votes
2answers
3k views

How to automatically record all your terminal sessions with script utility

What I want to achieve is be able to record my terminal sessions to file automatically whenever I use Yakuake/Konsole. It's easy to achieve if at the start of my session I do: script -f ...
9
votes
5answers
3k views

What are good online resources for learning shell scripting?

I am a beginner to shell scripting. I have not yet hardly coded a single program, but I am interested in learning it completely. Can anyone suggest some good online resources which will guide me?
6
votes
1answer
180 views

Parallel execution of bash script

I have a table URL_Experiment in my database (mySQL database). I have 2 million URL links in this table. For each URL, I am checking if some particular text is present in the URL and updating the ...
3
votes
3answers
2k views

Execute remote script with local parameter value

How can I automatize this task? 1) You are at A. 2) You ssh into B. 3) You run a script at B, that needs a parameter known at A. First, I thought perhaps I could send the value when I opened the ...
0
votes
1answer
36 views

Need to grep for specific lines from ongoing log and save it in some file

So, let me start with the overall outcome that i want to achieve. There is just one log, which will have info on certain devices, that i am upgrading. I use "tailf log" to monitor the log. Now, ...
1
vote
1answer
29 views

Pressing tab after sourcing script file prints script related output

I have a script file in a directory. Its contents are as follows : #!/bin/bash ...
1
vote
2answers
42 views

Make Trickle get the correct $PATH

Trickle is a bandwidth limiting program. I have the following script for trickle. #!/bin/bash echo $PATH trickle -s -t 3 -u 200 -d 200 "$@" I have a script in ~/bin/ that want to run the script ...
1
vote
1answer
32 views

print all values of a file after removing some characters using grep

I have a file in which the values are stored as below. Assistant Professor at SASTRA University St John's memorial college Paul George Univeristy Department Chair at University of Texas I am ...
2
votes
3answers
99 views

Extracting characters after a particular text

I am extracting a page from website using cURL command. curl "www.google.com" -s | w3m -dump -T text/html > foo.txt The w3m command outputs the HTML page in a much more simpler format so that ...
2
votes
1answer
90 views

shell script construct array for file elements

I have a file named input_file which contains some lines. I need to remove certain characters in the line and store them in an array. So to remove the characters, I use the sed command and storing in ...
0
votes
1answer
65 views

What's the safest way to pipe an email to a script via procmail?

I have a simple procmailrc recipe that hands mail off to a script: LOGFILE=/home/foouser/procmail-log VERBOSE=yes MAILDIR=/var/spool/mail/foouser DEFAULT=/var/spool/mail/foouser SHELL=/bin/sh ...
1
vote
1answer
245 views

curl and grep commands output into a new variable

I am extracting information from a website. I designed the code in VBA and found that it is taking too long to execute. So, I have decided to rewrite the code in Unix script. I am extracting a page ...
2
votes
1answer
44 views

Why does AWK not like dots in one of two substitutions?

I'm trying to use AWK in a bash script to look for a placeholder string in a template file and replace it with the contents of a variable that (can) contain various special characters. Example: ...
2
votes
2answers
388 views

Use awk to split line into array and use that array's values in calling shell

First of all, my apologies for the somewhat clumsily worded title. If you can think of a better one, please feel free to edit. [EDIT: done] What I am trying to do is use awk inside a bash script and ...
1
vote
4answers
116 views

Bash Script to Sort Files into Alphabetical Folders on ReadyNAS Duo v1

I have an old ReadyNAS Duo v1 (Sparc) running an unknown flavour of Linux. I have a folder structure with 1,000+ files I want to move into a folder structure based on the first letter of the file ...
4
votes
5answers
1k views

Using $? in an if statement

function foo { (cd $FOOBAR; <some command> if [$? -ne 0] then echo "Nope!" else echo "OK!" fi ) } I am trying to write a function like the one above and place ...
-3
votes
1answer
36 views

why does the dollar sign cause this command to be executed?

test_script.sh: #!/bin/sh D1="$(dirname $0)" echo $D1 D0="(dirname $0)" echo $D0 What I type on the command line: $ ./test_script.sh Output: . (dirname ./test_script.sh) What significance ...
1
vote
2answers
172 views

How to check if string starts with value containing #, tab, and maybe space?

In my bash script, I want to check whether a string starts with # modified: or # new file:. In both instances, the character after # is a tab. In the latter instance, the character between ...
0
votes
1answer
73 views

Can I use an if statement to detect if bash and dash are being run interactively? [duplicate]

After looking around for a while I've found several good pages describing how to check and see if a bash script is running interactively and there seem to be several methods, but one of them that I ...
0
votes
1answer
167 views

How to execute Netscaler commands through a remote machine via SSH connection

I have been trying to execute some NetScaler commands like "bind" & "unbind" through a Linux Box via an SSH Connection. Now the Problem is, Manually we are able to enter & execute commands on ...
5
votes
1answer
56 views

Is there any guarantee that /usr/bin/env will exist?

Often I will see scripts begin with a shebang line that uses #!/usr/bin/env interpreter_name for whatever interpreter, with the rationale that different systems might have the interpreter that they ...
2
votes
2answers
75 views

Using Sed with Regex

I would need to edit the values in a file delimited by colons (:) I would like to replace the contents of the file by using regular expression. After a grep to confirm that the item exist in the file ...
5
votes
3answers
367 views

Using notify-send with cron

I am using Arch Linux with KDE/Awesome WM. I am trying to get notify-send to work with cron. I have tried setting DISPLAY/XAUTHORITY variables, and running notify-send with "sudo -u", all without ...