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
1answer
40 views

Matching a randomly generated integer with a specific place value in a string

In bash I want to prompt user for input in a script. Lets say the input is: #!/bin/bash echo "Please enter a number." read NUM # User enters "12345678" How can I use the next command to generate ...
1
vote
1answer
53 views

Bash Scripting and quotation

I'm reading a couple of books on bash scripting, and struggling to understand proper quotation and the use of IFS. Perhaps someone can help me with a small example involving filenames with quotes. ...
0
votes
2answers
23 views

Find-replace within hierarchy of XML files

I have around 350 XML files spread throughout the /abc directory. I would like to find all instances where the value of the alt attribute is exactly 'blah blah': <image alt="blah blah" src="../...
2
votes
1answer
59 views

File disappeared after move

I have used the following command hoping to move pdf files from \\netdrive\F1\F2\Source\ to another folder \\netdrive\F3\F4\Des\ Command: PushD "\\netdrive\F1\F2\Source\" &&(forfiles /...
0
votes
2answers
57 views

Importing variables in one shell script from another without executing the referred shell script

I have 2 shell scripts, file1.sh and file2.sh file1.sh #!/usr/bin/env bash export var1="/data/share" export var2='password' echo "Hello" file2.sh #!/usr/bin/env bash source file1.sh echo $var1 ...
0
votes
0answers
27 views

Unable to run python script remotely through SSH on ubuntu 12.04

I am trying to implement a networking model(functioning well on ubuntu 14.04) on my system(ubuntu 12.04), which involves connecting with nodes(machines) remotely and running python script on them. For ...
0
votes
1answer
5 views

(Linux) How to launch instance of an already running application in blocking mode?

For explaining I use Firefox, but it also happens with other applications, here's the script: $ cat ff.sh #!/bin/sh firefox http://superuser.com/ echo "$?" Let's say Firefox is closed, when I run $...
0
votes
1answer
23 views

Prepend file names in shell

I have 100 .png files in a folder say test.png, example.png, etc. I want to prepend them with New_ so that it will be renamed as New_test.png, New_example.png etc. How can I do it in shell.
0
votes
1answer
14 views

Unix, Shell Scripting

I am extracting data from an Oracle database and writing it into a flat file. I need the line delimiter to be FFLF. I am able to add the FF character but I am unable to remove the CR character. How ...
0
votes
0answers
9 views

Run shell command after svn update in PhpStorm and IntelliJ?

We have some scripts that autogenerate helper code files. We occasionally get errors (eg. during reviews) because we forgot to run a script to regenerate the code to reflect recent changes. I'd like ...
1
vote
1answer
23 views

Working with different implementations of cp across different environments

So I figured GNU's cp is different than OSX's (BSD). While OSX copies the contents of a directory that ends with a slash, or the directory itself without the slash, GNU/Linux just treats somedir and ...
0
votes
1answer
22 views

Add character before a very large file to send to a shell script

I am trying to run a shell script on a 31,65 Go json file. ./oetl.sh database.json I need to have brackets before and after the file. What I have in database.json : {..},{..},.. What I want : ...
-1
votes
1answer
22 views

How to write shell script to mount a sd card into a folder?

I need to write a shell script which should run on startup. In this script my aim is to mount my sdc dev into a folder . Normally if run mount /dev/ /foldername on terminal it will mount How can I ...
0
votes
3answers
43 views

Combine multiple lines in a file to a single line

I have a file as below.. "Field1"|"Field2"|"Field3"|"ufghjkrtyrtyfgh$" "Field1"|"Field2 continue on line 2 continue on line 3"|"Field3"|"ufghjkrtyrtyfgh$" "Field1"|"Field2"|"Field3"|"...
2
votes
1answer
4k views

Run script when a specific disk/memory card is mounted under OSX

How do I run a script when a drive is mounted under OSX? My usecase is that I would like to automatically copy images from my USB memory/harddrive when it is inserted in my USB card reader, and when ...
1
vote
2answers
38 views

Can i execute a Linux command on shell script?

Can i execute a linux command on my bash shell script. for example how can i execute ifconfig on shell script. when i execute the shell the output of ifconfig should come on terminal. is there any ...
0
votes
1answer
27 views

Scripting with tmux?

Can I script several bash/sh instructions to open and run in separate tmux panes? I have about 5 or so different commands that need to be executed simultaneously or consecutively. I usually type ...
4
votes
3answers
56 views

How to create linux user with only and only READ permission not EXECUTE and WRITE permission?

I have created user, e.g. ronly, now I want to give them read only access to few directories on other user home like abc/,xyz/,pqr/ so I put this ronly user in others means not created any group for ...
0
votes
0answers
25 views

How to automate putty commands when connection is through serial port?

Two files are there. I want to run trial .txt cmd in serial port connectivity with a hardware.pls suggest how to automate this. I will use these cmds repetititvely. Batch file cmds below sv.batch ...
0
votes
0answers
22 views

sed command removes parent closing tag in xml file

Iam using sed command to replace a string with another in an xml file using below given the command. sed "s/one/two/g" /data/common/codeset-mapper.xml > /data/codeset-mapper.xml But the closing ...
0
votes
0answers
11 views

How to write the shell script which check if the file is present on the cluster file system?

Suppose we have pscp on Windows, and remote control to Linux cluster through key key.ppk, the user and host is name@cluster.com. How, by using shell script (in cmd file), check if some file is present ...
0
votes
1answer
21 views

Implementing changes via script

Learning stage of understanding script. I have to make these below change on every new system. So I created these script, unfortunately it isn't working. I want to understand that if the user input ...
-1
votes
0answers
13 views

create file with users input

How to create a new file which is created and modified at the same time, with the users input. for example: !/bin/bash echo "which Doc" read Doc echo "which DNS_FLG" read DNS This should read ...
0
votes
2answers
14 views

Monitor log live for error. If error = rerun command and restart log monitoring, if not found = keep monitoring forever

A process in a bash script I'm developing often fails quietly (it keeps running with no error code, but it writes the error in its log file). As soon as the error appears in the log file I want the ...
1
vote
2answers
121 views

Run a Windows application without displaying its GUI

Is there a way to run a Windows application without displaying its GUI window? I have a 3rd party Windows application which does not have any command line parameter or switch to suppress its GUI. I ...
2
votes
1answer
30 views

How to set different shell prompt color for each newly opened terminal

I am using Ubuntu and can manually change the bash shell prompt color to green using export PS1="\e[0;32m[\u@\h \W]\$ \e[m" However, I want the shell prompt color to automatically change whenever I ...
0
votes
2answers
397 views

How do I call function after prompt for input in a Linux shell script?

The title says it all. After Im prompted, I want yes and no to respectively call a function. # Check to see if you ran this script before echo echo I need to know if this is your first time... while ...
8
votes
2answers
25k views

How can I compare a variable to a text string, rather than integer, in an if/else statement?

In the process of writing a shell script, I ran into an issue with the following if/else statement that falls somewhere in the middle of the script: if [ $act -eq "add" ] then read - "add or ...
24
votes
11answers
93k views

Populating Array in DOS Batch Script

How can I setup an array variable in a DOS batch script? I would like to load it with a list of file names to process. I really would like to keep this as simple as possible. Thank you.
6
votes
4answers
6k views

Test if a package is installed in APT

I want a shell script method to test/report if a package is installed. I don't need details, only boolean return to set logic flow. I looked at Find if a package is installed, but dpkg returns complex ...
0
votes
1answer
54 views

arithmetic operation on a nested column in a tab delimited file

I have a tab-delimited text file containing Column1...Columnn columns and R1 to Rn rows. Within some of the columns, there are multiple nested fields with an identifier and then separated by semicolon ...
0
votes
1answer
31 views

How to create a specific folder structure inside multiple subfolders

I have a folder structure that looks like this drwxrwxr-x+ 9 root admin 306 May 3 10:19 . drwxrwxrwx 15 root admin 510 May 5 16:14 .. drwxr-xr-x+ 3 root ...
0
votes
3answers
3k views

Shell Script Error using Cygwin

I got this error after execute shell script as below. $ ./script_test.sh ./script_test.sh: line 3: syntax error near unexpected token `$'do\r'' '/script_test.sh: line 3: `for ((j=0; j<"$N"; j++)) ;...
0
votes
1answer
33 views

How to pipe binary stdout to a compressed tls connection?

Not so long ago, I could use : cat somefile.txt | openssl s_client -connect server:port -quiet -comp However, this command doesn’t work, even with-ign_eof: $ cat somefile.bmp | openssl s_client -...
0
votes
1answer
24 views

To create shell script

I want to create a script to check size of all the files present under particular folder, and if size of any file present under a folder cross 500mb it would trigger a mail to me specifying the file ...
2
votes
1answer
2k views

How can I tell if the lock screen is active from the command line on OS X?

I have a cron script that I want to run regularly if I am logged into my Mac. I don't want it to run if the Lock Screen is up. Is there a way to check from the command line / Terminal if the Lock ...
1
vote
1answer
35 views

How to pass array to bash shell script?

How do I pass an array as a variable from a first bash shell script to a second script. first.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') sh second.sh "$AR" # foo sh second.sh "${AR[@]}" # foo ...
1
vote
1answer
21 views

Accessing array index variable from bash shell script loop

I want to access the array index variable while looping thru an array in my bash shell script. myscript.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') for i in ${AR[*]}; do echo $i done The result ...
3
votes
2answers
828 views

How can uptime be used to trigger an action?

I want to write shell or perl code which would give me notification after x days. Basically on SUSE Linux server, there is reboot required after 208 days, else the system would freeze. This is known ...
0
votes
1answer
52 views

searching the string with the time in log file using shell script by passing variables

I want to search a string and subtract the time that is found from the current time. When used, the script should show the lines from that time or from the very next log time frame. I'm able to ...
1
vote
2answers
1k views

How to remove blank lines in .txt files

I want to change a text file's format, removing all blank lines. How can I do that? (2) 5. The function of the condenser is to: a) vapourise the liquid refrigerant b) change ...
1
vote
2answers
97 views

How can I elevate my cmd prompt using the the cmd line

I follow this script "runas /profile /user:administrator\administrator cmd"and when it prompts me for my password it always says that it is incorrect even though i am spelling it correctly. help ...
0
votes
1answer
40 views

How to run a shell script from an AppleScript?

I am using a Mac running OSX Yosemite v.10.10.5. When I try to run my shell script from my AppleScript, I get the following error message: Error message at AppleScript Script Editor error "sh: /...
0
votes
1answer
24 views

Shell Save the array element values in the variables

I need to copy the files from one folder to another, here source and destination information are in the text file. File content: res.txt /var/lib/jenkins/jobs/Android\ Gradle\ test\ build/workspace/...
0
votes
1answer
31 views

Bash script to find content of file in a directory and add value

I have a directory with a huge number of files. I want to write a bash script to - Enter that directory Find out which of them are Perl scripts (but none of them have a .pl extension) Add a line at ...
0
votes
2answers
63 views

Fetch required column from a file with \001 delimiter

I am storing output of pig file in a directory Which contains lines with multiple columns separated by delimiter \\u0001. Now in shell script I want to fetch 7th column field from the output. I ...
1
vote
1answer
533 views

script for auto adding routing table entries

There are a lot of remote agents that use Mountain Lion. We want only the directories on our intranet to be go through the VPN tunnel and all other traffic to go direct out. So to do this I had to add ...
0
votes
2answers
26 views

Evaluate each environment variable and set it back in ubuntu

I'm trying to write a shell script which reads all the environment variables, evaluate them for included env. variable with in them and re-export after evaluvation. Example - I've an environment ...
0
votes
1answer
29 views

How to programatically modify systemd unit files?

I'd like to edit a systemd's unit file from a shell script. I want to change the unit's only ExecStart line. Using systemctl edit looks smart to me, but the command needs an editor set as ...
1
vote
0answers
17 views

Detecting new USB devices with bash?

I'm writing a bash script that needs to detect when a usb storage device is inserted and assign it to a variable that would otherwise, typically look something like: usb=/dev/sdb. I have a few ...