A shell script is a script written for the shell, or command line interpreter, of an operating system.
3
votes
2answers
1k views
Executing a shell script from remote server on local machine
Imagine a shell script on the remote server as
#!/bin/bash
rm /test.x
How can I (if possible) to execute this script from my local machine to delete /test.x file on my local machine. Obviously, the ...
0
votes
1answer
92 views
How to delete number of lines from file repetitively
I've read How do I delete the first n lines of an ascii file using shell commands?, it is helpful. However I've a file something as below (please consider 2 columns as 2 different files):
1 4
1 4
1 4
...
3
votes
1answer
170 views
Pausing rsync via bash script?
Is there a way to pause rsync via command line, if it transfers data for over X minutes? I'm working on using it as a backup and would like it to pause every once in a while to prevent the hard disks ...
3
votes
5answers
281 views
Remove lines based on pattern by keeping first n lines
I need to remove lines from a text file based on pattern but I need to keep the first n lines of that pattern.
Input
% 1
% 2
% 3
% 4
% 5
text1
text2
text3
output
%1
%2
text1
text2
text3
I used ...
0
votes
1answer
88 views
How do I write a script to keep retrying Yum Update Program?
My job let me always release a new version of the program to a satellite server, then in the running server, I use yum update program to update the program.
However, due to unknown reason, in most of ...
2
votes
2answers
638 views
how to move (not copy) files from one server to another?
I want to move files from server1 to server2.
A producer on server1 will keep generating the files, and a consumer on server2 will keep processing them.
I can copy files using the following shell ...
3
votes
2answers
100 views
Make copies of a single directory to multiple directories with different names
I'm trying to replicate a single directory (with sub-directories) to a bunch of new directories based on a list. For example I can:
mkdir Fred Barney Thelma Louise Foo Bar
How would I copy a premade ...
-5
votes
1answer
73 views
Counting the number of files with in a diectory with a pattern but pattern dosen't know [closed]
To count the files in a directory having some pattern for some files, but we don't know the pattern, then How to count than particular pattern files?
For Example
If a directory has xx_1.txt, ...
0
votes
1answer
300 views
Shell script to delete all files which are older [duplicate]
Possible Duplicate:
Deleting files by age
Write a shell script to delete all the files which are "n" of older that current day, where n can be 3days. 2days, or 1 year etc. The above script ...
3
votes
1answer
189 views
Need to improve urlencode function
I need a way to URL encode strings with a shell script on a OpenWRT device running old version of busybox.
Right now I ended up with the following code:
urlencode() {
echo "$@" | awk -v ORS="" '{ ...
1
vote
1answer
230 views
Identify text/ascii files in Linux/Solaris
I have a little project to build bash script that search in the OS ( Linux/Solaris ) the current IP address from files and replace them with other IP address.
The problem is that IP address could be ...
2
votes
2answers
610 views
Concatenate multiple files with same header
I have multiple files with the same header and different vectors below that. I need to concatenate all of them but I want only the header of first file to be concatenated and I don't want other ...
0
votes
2answers
89 views
file command + how to view all results from file command
I use the file command in order to verify if file (PATH) is text/ascii file or encrypted file
Because file command have allot of results ( small example in example 1 )
I want to get the all ...
3
votes
3answers
153 views
Zsh function with su and echo
I'm trying to add a function to my .zshrc that makes adding new USE flags to my /etc/portage/package.use file easier. Normally, I'd have to do
su -c 'echo "net-misc/aria2 bash-completion bittorrent" ...
1
vote
1answer
122 views
Environment auto-install script
When I work, I often have to switch computers or virtual machines which means that every time I switch, I have to set up my (Linux) environment again.
Is there a tool (in contrast to a simple bash ...
1
vote
2answers
203 views
Convert discus output into readable HTML mail
How can I take the DISCUS command output below:
and convert it into something HTML email friendly? I've bash scripted something like this:
#!/bin/sh
discus > /tmp/discus.log
touch ...
1
vote
4answers
454 views
gpg asks for password even with --passphrase
I expect the following command to extract the gpg file without asking for password:
gpg --passphrase 1234 file.gpg
But it asks for the password. Why?
This also have the same behavior:
gpg ...
1
vote
3answers
281 views
linux/solaris + verify duplicate valid IP address from file
what the best way to find duplicate IP from file ( I have ksh script in this script I need to write function that check for duplicate IP )
for example if IP - 192.1926.23.52 exists twice in file - ...
0
votes
4answers
987 views
/shell-script: syntax error near unexpected token `done'
I am getting syntax error near unexpected token done while executing my shell script:
while read filename
do
echo "$filename"
if [ -s $filename ]; then
tail -10 $filename | grep `date ...
3
votes
2answers
674 views
sed: multi-line replace of config block
I have some configuration files that basically look like
(...content...)
# BEGIN DYNAMIC BLOCK - DO NOT EDIT MANUALLY
(... more content ...)
# END DYNAMIC BLOCK
(... even more content ...)
Now, in ...
0
votes
3answers
223 views
How to match a file name suffix
How to verify if the name of a .xml file name ended with .any-string? e.g. .previous or .backup or bck12 etc ...
I need to print the XML file name except for XML files that end with ...
3
votes
1answer
200 views
Color script output only when invoked from interactive shell
I made a bash script producing colored output. The colors are fine when the script is called from an interactive shell. However, if the output is processed in another script, or passed through a pipe, ...
5
votes
4answers
290 views
Tool to create text files from a template
I have to regularly create 100+ text files from templates.
I currently use an overly complicated shell script. I think there is a smarter way to handle this, but I don't know how.
I have a "database" ...
3
votes
1answer
385 views
Capture screen content for error parsing
I am a database administrator working with DB2 on AIX. (Please continue to read as this is related more to ksh than DB2, otherwise I would have posted this over on dba.stackexchange.com.) I am ...
3
votes
2answers
225 views
Error when subtracting two negative numbers in ksh: “assignment requires lvalue”
I am trying to debug someone else's script:
The code line is:
y=$((${oldvalue[$x]}-${newvalue[$x]}))
y gets calculated fine as long as both sides are positive numbers. However, I have a ...
5
votes
2answers
609 views
How to continuously take backup of log files?
I have some applications in Lunux which creates Log files of around 41 MB each. The log files switches from log.1 to log.2 and starts overwriting log.2 once this 41MB is completed in log.1 file.
I ...
3
votes
4answers
409 views
bash string extraction
I would like to extract the 2nd field from the last part of the following strings:
foo_1.103.debug_xx.ver21-inc-1 --> string extracted "debug_xx"
foo_1.103.1.0.release_32_xx.ver21-inc-1 ...
2
votes
1answer
410 views
Bash variable in Awk script
I have this flat file database(ff_servers.db) with following contents:
192.168.154.2 Alaska hp
192.168.157.3 Colorado dell
192.168.156.3 hawaii hp
From command line, I could run:
awk ...
3
votes
2answers
196 views
Shell script debugging
I was wondering if there is an IDE that would allow me to define an ssh connection to a remote host, connect, and locally debug a script running remotely (kind of like you can debug a remote Java app ...
2
votes
1answer
59 views
Listing script's file dependencies
Given a shell script, is there an easy way to extract what files it manipulates explicitly (so not like concatenating some command and than eval-ing it)? E.g.
#!/bin/bash
. /etc/someconfig.cfg
...
4
votes
1answer
161 views
what is the zsh equivalent of bash's export -f
So I started using zsh. I like it all right. It seems very cool and slick, and the fact that the current working directory and actual command line are on different lines is nice, but at the same time, ...
3
votes
3answers
631 views
Preserve directory structure when moving files using find
I have created the following script that move old days files as defined from source directory to destination directory. It is working perfectly.
#!/bin/bash
echo "Enter Your Source Directory"
read ...
2
votes
2answers
99 views
Does a parent bash script remember the cd history from a child bash script?
Example:
mainscript.sh
cd /mnt/something
./buildscripts/000-script.sh
000-script.sh
cd /mnt/otherthing
mkdir something
exit
-1
votes
1answer
107 views
Error while running bash script that moves files
I am new to bash script and want to create bash script that moves some days old files between source and destination as per days defined in script.
When I run this script I get error
find: paths ...
0
votes
1answer
64 views
Why is this variable not getting passed to awk? [duplicate]
Possible Duplicate:
external variable in awk
How do I pass this variable below?
This doesn't work:
fname=testfile.txt
lsof | awk '/deleted/&&/$fname/ {print $4}' *----no output*
...
0
votes
2answers
142 views
Shell script that copies while adding a user-provided filename suffix
I'm trying to write a shell script on Solaris that copies files from one directory to another. I need it to prompt the user for a date, and add that as a suffix to the destination filenames. How do I ...
2
votes
1answer
63 views
How to set Cols and Lines for a Subprocess
I have a script that runs a series of scripts numbered 001,002,003,004... etc down to 041 right now, will be more in the future - and these scripts them selves use some cursor control to print a ...
3
votes
3answers
118 views
SSH to two addresses, use the one that connects first
I have a home computer (let’s call it franklin because that’s what I call it) that I often ssh into from my work laptop. When I’m at home, I ssh to franklin.local, and when I’m at work or anywhere ...
0
votes
1answer
166 views
difficalty to save traceroute output in shell variable?
I need to filter and store traceroute output in shell variable (array). But I am getting some unusual output.
As I try to explain in following lines.
My present directory is temp, having some ...
2
votes
2answers
283 views
print a file in hex using awk
I have a file name x
$ cat x
1A34532112345
I wants to print in hex using awk I written a script (with help from web)
fold -1 /home/cscape/Desktop/x | gawk '{ printf("%s , %X\n",$0, int($0) )}'
...
2
votes
3answers
153 views
Indent like first line
How can I indent a file such as its first line?
Example:
A file containing
x=1+2+3+4+
5+6+7+8
+9+10+12
should be converted to
x=1+2+3+4+
5+6+7+8
+9+10+12
I need this inside ...
2
votes
1answer
334 views
Find all folders in a directory with the same content
In Ubuntu, is there any to find duplicate folders in a directory (i. e., folders with the same content)? I think there are already some command-line tools available for finding duplicate files (such ...
1
vote
2answers
85 views
Extra % in output of awk script
I have the following script in awk that sums all columns in a file that I pipe to it:
#sum_all.awk
{ for (i=1; i<=NF; i++) { sum[i]+= $i } }
END { for (i=1; i<=NF; i++ ) { printf "%d ", ...
4
votes
3answers
283 views
Is there a way to call a command with a set time limit and kill it when that time passes? [duplicate]
Possible Duplicate:
Run a command for a specified time and then abort if time exceeds
I was working on a continuos integration build script when a need for such a command arose. Basically ...
0
votes
1answer
76 views
why there is random behaviuor for a background job?
going through advanced bash scripting guide example 3.3 running a loop in background, i found this :
#!/bin/bash
# background-loop.sh
for i in 1 2 3 4 5 6 7 8 9 10 # First loop.
do
echo -n "$i "
done ...
0
votes
1answer
140 views
How to make a scheduled task based on a file creation time?
The supercomputer I run my Analysis uses SGE to do the job management and requires each job duration not longer than 24 hours. And this feature is causing me quite a headache.
Sadly, I was asked to ...
0
votes
1answer
412 views
Linux + replace STRING/WORD in file according to rule
My target is to replace any word/string/Any characters in file
with new word/string according to the following rules:
If numeric characters on the left side of word/string then we not replace the ...
1
vote
0answers
36 views
mapping Character keys
I really dont understand bash`s use of control characters. I understand simple things like adding colors with escape sequences but am at a loss for how to do things like bind keys in .inputrc
For ...
0
votes
1answer
229 views
linux + perl + replace any WORD in file with special characters with condition
Example1 work fine when I want to replace OLD_TEXT with NEW_TEXT ( its replace also all special characters as $@^%)(_+`:; etc ..)
example1
export OLD_TEXT='$$OLD_WORD$$'
export ...
3
votes
3answers
552 views
In Unix speak what is the difference between a shell script and an executable?
I have seen this question on this site and this prompted me to ask this question . I want to know in Unix speak what is the difference between an executable and a shell script ?
