Questions tagged [shell-script]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
313 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 $ ...
816-8055's user avatar
  • 1,267
0 votes
1 answer
120 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.
S6633d's user avatar
  • 27
0 votes
1 answer
29 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 ...
Cron's user avatar
  • 1
1 vote
1 answer
953 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 /m *...
Bolu's user avatar
  • 113
0 votes
1 answer
61 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 : [...
AlexB's user avatar
  • 103
-1 votes
1 answer
952 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 ...
Karthik Shivanna's user avatar
2 votes
1 answer
236 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 ...
Simone's user avatar
  • 145
2 votes
2 answers
5k 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 ...
varza's user avatar
  • 21
0 votes
1 answer
3k 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 ...
voices's user avatar
  • 2,731
3 votes
3 answers
827 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 ...
chintan thakar's user avatar
0 votes
0 answers
372 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 ...
Mathew's user avatar
  • 117
0 votes
1 answer
43 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 ...
AReddy's user avatar
  • 193
0 votes
2 answers
1k 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 ...
NewsGuy's user avatar
1 vote
3 answers
1k 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"|"...
Viswakanth's user avatar
5 votes
2 answers
8k 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 ...
AllSolutions's user avatar
2 votes
1 answer
322 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 ...
manav m-n's user avatar
  • 353
1 vote
1 answer
160 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 a ...
Yokai's user avatar
  • 299
0 votes
1 answer
244 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 ...
Richie086's user avatar
  • 5,201
0 votes
2 answers
1k 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 -...
user2284570's user avatar
  • 1,843
0 votes
1 answer
42 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 ...
Mohit Deokar's user avatar
1 vote
1 answer
4k 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 ...
Mowzer's user avatar
  • 2,299
1 vote
1 answer
1k 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 ...
Mowzer's user avatar
  • 2,299
0 votes
1 answer
1k 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: /...
Mowzer's user avatar
  • 2,299
0 votes
1 answer
1k 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/...
Nagaraj ks's user avatar
0 votes
1 answer
165 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 ...
Suraj Bhatia's user avatar
0 votes
2 answers
2k 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 ...
Kishore Bandi's user avatar
6 votes
1 answer
4k 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 ...
yanana's user avatar
  • 163
1 vote
1 answer
2k 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 ...
voices's user avatar
  • 2,731
0 votes
1 answer
627 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 ...
user267747's user avatar
0 votes
3 answers
16k views

Shell script Copy file from one directory to another not working

Hi I am trying to automate the android build system through jenkins. Here I am trying to copy the image file from one directory to another directory but always getting " No such file or directory" ...
Nagaraj ks's user avatar
0 votes
1 answer
270 views

Shell Script excuted fail in Linux at command

When I run a Linux "at" command,I find the user's shell script executed fail, for example,I write the following code in my script #!/bin/csh #or #!/bin/bash echo "Now will excute a shell script" ...
Liuwei.Shi's user avatar
1 vote
1 answer
4k views

Shutdown a linux computer depending on the battery level

Is there a way to shutdown a linux-based computer when the battery charge drops below a certain level? I have searched through the shutdown and poweroff manuals but found nothing relevant.
atsag's user avatar
  • 71
1 vote
1 answer
3k views

How to run script in same session without exec?

I have below script to set me in my project:- #! /bin/zsh source ~/.zshrc crld #alias for Project base cd Kenneth_Love/survivalguide workon kenneth_tutorial This script works but doesn't drop me in ...
user1517650's user avatar
46 votes
3 answers
194k views

How to POST file contents using cURL?

I want to do an HTTP POST of the contents (as a string) of a local file located at path/to/my-file.txt to a URL endpoint at http://example.com/. For example, I might want to do the following: ...
Mowzer's user avatar
  • 2,299
-2 votes
3 answers
2k views

How can I write a bash function that checks if an integer is even or not?

How can I write a shell predicate function event that takes an integer argument and tests if it's even or not?
max's user avatar
  • 1
0 votes
2 answers
1k views

new column to a tab delimited file, with as predefined value

How can I add a new column to a tab delimited file, at the end of the file, containing the same values for each row. For example: infile.txt Name Age Address Sex X 12 adrs1 M Y 15 adrs2 ...
panbar's user avatar
  • 1
2 votes
1 answer
623 views

Merge only new entries from one xml file to another

I have 2 xml files. The 2nd file has some new entries including same entries as that of the 1st file. Examples of the 2 files are given below. File 1 <SERVERNAME_ONE> <Protocol>...
Mathew's user avatar
  • 117
0 votes
1 answer
134 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 ...
panbar's user avatar
  • 1
0 votes
2 answers
678 views

simple arithmetic operations on a tab-delimited text file in shell script

I have a tab-delimited text file containing C1...Cn columns and R1 to Rn rows. Column 10 (C10) has a field 'X'=four comma separated integer values (X=a,b,c,d). I would like do a small arithmetic ...
panbar's user avatar
  • 1
0 votes
1 answer
120 views

how to write a shell script to take password automattically after the execution of command

#!/bin/bash cd /var/SUNWdsee/ds6/bin ./dsconf show-repl-agmt-status -e suffix Hostname:389 Above is my script. After the execution of the last line it will prompt for password in screen. I need to ...
Vasanthshankar's user avatar
-1 votes
1 answer
441 views

dos2unix command is corrupting the file with unicode characters downloaded via binary mode

i downloaded an xml file having unicode characters from ftp in binary transfer mode. In order to remove the line ending special characters i used the command dos2unix. But this is making the file ...
Mathew's user avatar
  • 117
0 votes
0 answers
20 views

cronjob not finding commands [duplicate]

I am running (and also new to) OS X El Capitan. I have a user cronjob that is using some basic commands that I got via brew. wget and s3cmd I have the cronjob executing a shel script in my user bin, ...
Joff's user avatar
  • 227
1 vote
0 answers
1k views

Colon(:) operator in Unix shell

As far as colon is concerned i understand that is is used in certain situations as a null and as a parameter of expansion for substring, but can someone explain me this: do_qc: $(STAGE1_OUT_FILES) ...
Daniel Moreira's user avatar
3 votes
1 answer
3k views

pass du (disk usage) result to a numeric variable

In a shell script, I'm looking for a way to pass the du (disk usage) result to a numeric variable, so that I cantie the execution of a shell script to the size of a specific folder. I've tried ...
brunobhr's user avatar
0 votes
1 answer
2k views

Rename folder on remote server

I am calling a .bat file which contains the following command net use \\128.545.k.k\E_Drive /user:Username psw to connect to a remote server. I would like to rename a folder on the remote server i ...
jane08's user avatar
  • 3
3 votes
1 answer
446 views

Emacs: suppress indent after && in shell-script-mode

In shell-script-mode, when a line ends in &&, Emacs will indent the following line. Is there a way to switch that off? (I am concatenating most of my statements with &&. This gives ...
Lasse Kliemann's user avatar
0 votes
2 answers
46 views

Unable to add spaces

How can i add spaces between my outputs using sed/echo or any other command in linux? Preferred Output: Virtual Machine Test01 status Running. Virtual Disk Test01 size 61GB Physical Disk ...
biz's user avatar
  • 29
0 votes
1 answer
88 views

Duration time between cycles in a log file

My apologies if this is too basic, but I have a log with this kind of information: Mai 5 12:34:00 xoengine XO[1287]: [Xo|xoengineMain.cpp:122|0xb88ec60] starting xoengine 4.0.1.2 (x86) from [/usr/...
user avatar
0 votes
1 answer
329 views

Cannot execute ssh-ed osascript properly inside of shell script

I have created a ip-down script in my etc/ppp/ directory. Essentially I am trying to kill certain programs/servers when the VPN disconnects, then display a notification on another computer via ssh. I ...
TYPKRFT's user avatar
  • 13
6 votes
3 answers
11k views

The "other" finger (GECOS fields at /etc/passwd)

in the file /etc/passwd we have the so called GECOS fields (which stands for "General Electric Comprehensive Operating System"), that is: username:password:userid:groupid:gecos:home-dir:shell Where ...
DrBeco's user avatar
  • 2,005

1
11 12
13
14 15
29