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)

5
votes
1answer
189 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. ...
3
votes
5answers
212 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
0answers
45 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
2answers
118 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 ...
0
votes
2answers
33 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 ...
2
votes
4answers
79 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 ...
1
vote
1answer
62 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
115 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?
0
votes
0answers
58 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
3answers
397 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
455 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 ...
6
votes
2answers
336 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 ...
20
votes
2answers
619 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 ...
1
vote
2answers
147 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
3k 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
73 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
361 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.
1
vote
3answers
200 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?
0
votes
2answers
217 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
2answers
67 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
3answers
250 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
63 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 ...
4
votes
3answers
149 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. ...
2
votes
1answer
369 views

Differences between %pre and %post in Kickstart on CentOS?

I have been setting up machines with Kickstart on CentOS and I am unsure about the differences between the %pre and %post sections of the kickstart .cfg file. The CentOS Documentation for the ...
7
votes
1answer
212 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 ...
0
votes
1answer
48 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
38 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
1answer
64 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
339 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
191 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 ...
1
vote
2answers
58 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
1k 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 ...
0
votes
1answer
118 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 ...
2
votes
1answer
58 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
2k 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 ...
-3
votes
1answer
58 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
983 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 ...
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 ...
0
votes
1answer
178 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 ...
5
votes
1answer
79 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
93 views

How to split files with common prefix in bash

I have a directory with many files with common prefix, like gsc*_other.foo, where * is a character that goes from 0 to 9 or a/b (where a stands for 10 and b for 11). My goal is to create text files ...
2
votes
3answers
37 views

setting up script in a linux machine for scientific computation [closed]

I'd like to setup machine for test some computation in my old laptop, before replicate the tests on the server. The computation will be image-processing and machine learning, run some program, load ...
0
votes
1answer
406 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 ...
2
votes
2answers
82 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 ...
1
vote
2answers
48 views

Is this an array?

I'm currently looking at an existing script that have something like this: variable='val1 val2 val3 val4' Is this another way of setting an array? If not, what is it?
5
votes
3answers
886 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 ...
3
votes
2answers
586 views

Human readable dmesg time stamps on OpenWRT

The output of dmesg shows the number of second+milliseconds since the system start. [ 10.470000] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver [ 14.610000] device eth0 entered ...
1
vote
4answers
440 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 ...
5
votes
4answers
160 views

Prefixing and appending blocks of text to a list of files

I'm trying to prefix and append blocks of text to a list of files. Here is where I am so far. The sticking point is the sed -i "1i \$prefix" "$file" && line. sed won't substitute the value of ...
-2
votes
1answer
80 views

automatic capturing top output by cronjob CENTOS 6.5 x86_64

I have this command: top -n 14400 -a -b -d 1 > /toplogfile.txt I want to make a script which is run by cron every day to capture top output, and if it is possible gzip the output file after the ...