Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

0
votes
0answers
22 views

Run a command stored in a variable [duplicate]

I am working on updating some scripts we have used previously ( on RHEL) to work for a new flavor of Linux (ESX). As I am modifying the script, I wanted to add user feedback as well as some other ...
0
votes
1answer
56 views

How to clear log files periodically

Hi I am new to Shell script. i want to clear log files in a directory basing on the dates. I have managed to gather this code: DIR1='/home/u01/app/oracle/servers/DIR1/logs' ...
1
vote
2answers
48 views

How can I delete <93> <94> symbols in file? It is equivalent “ ”

I copied text from a PDF file in bash - vi and I get lines like this: echo <93>The Hypotenuse is $hypotenuse<94> I tried to change that in vi by: s/<93>/"/g But: E486: ...
4
votes
6answers
241 views

Loop in text files shell script

I have a list of files in one directory and a set of jpegs corresponding to each file in another directory. I need to loop over all files, and for each file name, determine the target directory. For ...
0
votes
1answer
30 views

A script to install OpenVPN & modify iptables?

I d like to automatize the install/config of OpenVPN on my client machines. Roughly, it should looks like : - apt-get openvpn - cp, edit, .... - modify iptables. Is it possible in one script ? or am ...
0
votes
1answer
40 views

How remove duplicates in same file and with if condition?

INPUT FILE: has all these values without header: customer ID, code, start_date, end_date 124343, DCW, 2015-07-06, 2016-08-03 235432, ABC, 2015-04-26, NULL 235432, ABC, ...
2
votes
4answers
128 views

How to see if there are any matching characters in a string?

I'm making a card hand generator, and I want it to note if a specific hand is generated, like a three of a kind or a full house. I was trying to figure out how to do it, and I thought of using grep on ...
0
votes
1answer
21 views

Creating service in SLES / SUSE 11 SP3

I have a python script that works very well executed from a (remote) console like this : sudo /srv/web-asset-server-master/python server.py The problem is, that it only lives as long as the console ...
-4
votes
3answers
51 views

find and replace strings with another string command line

I have a Ad-blocking hosts file with 0.0.0.0 IPs pointing to URLs. How to replace 0.0.0.0 with 127.0.0.1 command line without any visual text editor ? Manually doing this with nano , vi etc. is ...
0
votes
2answers
32 views

Where should startup scripts for a specific user be installed?

I have one script that will run when a specific user logs in. Where should this script and its assets be placed? I was planning to put it in /usr or /bin or /var, but I was wondering if there's a ...
0
votes
1answer
28 views

Terminal doesn't calls 'then' a syntax error, command not found [closed]

I am a newbie for linux. I have centOS7. I am running a very simple script from BASH. I execute the chmod command and then run the script file from terminal, I get an error saying that if command not ...
2
votes
3answers
42 views

Find strings in file1, count occurrences in file2

I have file1.txt with string values such as New Drug Application Drug Product Dosing instructions I need to count how often these strings occur in file2.txt with data such as Regulatory New Drug ...
1
vote
0answers
18 views

APCUPSD script can't close program

I want to use APCUPSD to stop a program (called ns_image_server) which runs in a terminal window when it detects that power has been lost, to give that program time to close before the computer shuts ...
1
vote
1answer
40 views

Passing multiple varibles to a script for SQL query

I have this script called info_code: #!/bin/ksh if [ $# -eq 0 ] ;then echo "Enter code : \c" read code echo "" else code=$1 fi code=`echo ${code} | tr '[a-z]' '[A-Z]'` echo "select * from ...
6
votes
5answers
104 views

How to find the next available file suffix (file_a.txt file_b.txt etc)

My system creates a new text file every time a certain event occurs. The files should be named file_a.txt file_b.txt file_c.txt etc. In a Bash shell script,how to find out what filename should be ...
0
votes
2answers
83 views

Using multiple awk commands within single line

Here is what am trying to do: My data is in sets of rows within same file (the variables vaa vbb are looping over it and am able to control it as required) What i need is to add an extra column before ...
1
vote
1answer
68 views

When to use #!/bin/ksh and #!/bin/sh? Need example [duplicate]

Also what are the main differences between these two. To execute a script is it necessary to write this at the beginning of script?
0
votes
3answers
67 views

In bash, how to call a variable and wrap quotes around its value as part of a command without causing the variable name to become a string literal?

So I want to add 10 seconds to a time. The command to do that came from here. To illustrate: STARTIME="$(date +"%T")" ENDTIME="$STARTIME today + 10 seconds" CALL="$(echo date -d $ENDTIME ...
1
vote
2answers
52 views

Using df and trying to awk a specific column

Among other problems with this script I am trying to make (this is the first unix/linux script I have ever made), I am trying to use df to get the % of disk space used and email it to the root. Our ...
3
votes
2answers
62 views

check for “errors” or “ORA-”

I want to check for "errors" or "ORA-" in Y.if there is an error then exit Y=`sqlplus -s user/passwd<< EOF exec test_Proc; exit; EOF` if [ echo $Y | awk '/ERROR/ || /ORA-/' ] ; then exit 1 fi ...
8
votes
2answers
324 views

Why does printf print more arguments than expected?

Why is this shell script printing inputs twice? I expected the script to ignore the inputs after 5. Script: #! /bin/bash echo "Enter 5 words : " read a b c d e printf "> %s %s %s %s %s <" ...
2
votes
3answers
60 views

Run a task in background and know the time of its termination

I need to run a unix shell script (my_script) in background and monitor it from web interface. I start the actual script from php like so: $command = 'my_script'; $pid= exec("nohup {$command} > ...
1
vote
2answers
36 views

Is it possible to have bash variables persist between runs

I am trying to create an init script which queries losetup -f for a free loop device. Within the init script I have a start() which queries losetup -f for the free loop device to setup some stuff, and ...
1
vote
1answer
35 views

Obtaining unique lines with matching strings [duplicate]

I have a JSON like text file of records with duplicate ids that look like: {"ID":"93" , "ST":[42,77,51]} {"ID":"21" , "ST":[43,4]} {"ID":"94" , "ST":[65,11,4]} {"ID":"93" , "ST":[42,77,51,29,63]} ...
1
vote
2answers
51 views

/bin/sh - echo >> operator not working as expected

I'm writing a shell script that appends binary contents to a file. I tried using this command: echo -en '\x61\x62\x63..' >> /tmp/myfile but that caused the following output: -en ...
2
votes
1answer
50 views

script running in crontab not giving output on shell screen

I am trying to run a simple echo script via crontab. I set that to run every minute, but it doesn't give output on shell screen. However, it runs fine when I run the script independently. Script ...
1
vote
0answers
67 views

sftp using socks proxy command with password authentication

I am struggling to make a sftp connection.We need to make a sftp connection to download files. My requirement is that we are moving from ftp gateway to axway and We were using ftp before to download a ...
0
votes
2answers
54 views

How to redirect unzip -v output to a log file in shell script [duplicate]

I have a script that loops through all zip files in a large directory and individually unzips them. I am using the -q option in order to keep the console clean and display other monitoring info. I ...
1
vote
1answer
66 views

Doing a 2>&1 redirection inside a script

Is it possible to run a script from within another script, and include a redirection into a log file? I'm attempting to run 3 scripts from within a larger script. One of them needs to be run "at ...
2
votes
3answers
653 views

What does “if $” mean in if $( ssh user@host “ [ -e file ] ” ); then …?

I saw script where the condition in an if statement used a $ and I don't understand why? if $( ssh user@host " test -e file " ); then echo "File is there" else echo "We don't that file on ...
1
vote
4answers
135 views

How to use and/or conditional in shell script

I have an if statement in a script. It looks like this: if [ "$a" != "0" -a "$b" != "100" ]; then #some commands here If I'm not mistaken, the line above will work if both conditions are true. ...
1
vote
2answers
84 views

CasperJS and PHP In Cron Job Cannot Open Files, Works Fine When Run Manualy

I recently got a new DigitalOcean LEMP environment with Ubuntu. I tried making an SH script that uses CasperJS to scrape data from an external website to a JSON file, and a PHP script to parse the ...
1
vote
1answer
68 views

Improving performance of script [closed]

I have been working on a script that can be used to automatically restart my Zabbix monitoring services in the event that they stop running. I have the script working just fine, but figured it could ...
1
vote
2answers
49 views

concatenating file names in a variable

I am attempting concatenate file names to use in a ftp mdelete command. Each file name needs to be separated by a space in order for the mdelete command to work. The $i variable is in a loop and I ...
2
votes
3answers
72 views

How to pipe output from cat to cut

I want to cat /proc/uptime into cut -f1 in a Bash script. I've tried; cat /proc/uptime | cut -f1 cat /proc/uptime > cut -f1 cut -f1 < cat /proc/uptime Do I need to use echo or something ...
1
vote
1answer
29 views

Why does this script give error?

Why does this script give error? #!/bin/bash # This script checks whether # the current user is root or # not. if [ $UID -ne 0 ] then echo "Non-root user." else echo "Root user." Fi ...
2
votes
4answers
82 views

pulling lines related to the date

I've got a text-file that's sorted by the first field, which is month/day (eg: 02-20) I've been using grep on rhe text file, but that's easiest to do with today's date, using the date command in a ...
0
votes
1answer
42 views

How can I use sed to find a string and replace another string on a different line? [closed]

I have a file like this: BEGIN Name "TIPO_RECORD" SqlType "12" Precision "255" Name "Test" SqlType "12" Precision "255" Name "xxxx" SqlType "12" Precision ...
0
votes
1answer
24 views

sending mail for frequently changing users

I want to use a control file where I have all my mail Ids stored in a directory say Ex: /abs/pqr/send_mail.ctrl Sample of control send_mail.ctrl abc@domain.com str@domain.in ------ ----- Now I ...
1
vote
2answers
38 views

Prevent certain lines of a script to run as root

Suppose I am writing a shell script that requires root privileges to run, for example- #!/bin/sh ip -s -s neigh flush all ufw enable How can I prevent certain lines of code to be run as root, i.e. ...
3
votes
2answers
102 views

Whats going on in this function?

log () { A=$1 print "`date '+%m/%d/%y %H:%M:%S'`: $A" >> LOGFILE.txt print "$A" } This is how log function used in most of the shell scripts in our environment. and its been used in ...
3
votes
2answers
70 views

Script for changing modification time of files and directories recursively

I have many big folders with thousands of files in them and I want to use touchto set their modification times to be "original time"+3 hours. I got this script from a similar thread in superuser: ...
2
votes
2answers
61 views

How to make this `echo | bc` output be on the same line as the echo output after?

I'm making a program for generating random numbers, and before it generates, I want to show how many combinations there are. When I do it, I get this: 64k@conroe$ bash random A-Za-z0-9 3 238328 ...
2
votes
3answers
101 views

extract string between double quotes

I have requirement that i need to extract string using quotes. My string as follows. "abcd efgh" "ijkl mnop" "qrst uvwxyz" can you help me to get the string between second double quotes(ijkl mnop) ...
3
votes
1answer
144 views

Bash substitution with variable defined from a glob pattern

The below example explains the issue. Why is the FILENAME printed correctly when echoed and perceived as a pattern when using substitution? #!/bin/bash FILEPATH_WITH_GLOB="/home/user/file_*" ...
2
votes
0answers
59 views

“: not found” and syntax error in my first ever shell script [duplicate]

The shell script, I am trying to create, should be run by crontab regularly, and it should call a perl script which saves email attachments to a predefined directory. Here's what I came up with: ...
1
vote
0answers
32 views

Problems with kpartx in a script

I am trying to run the rpi-image-creator script (see https://github.com/ImmobilienScout24/rpi-image-creator/blob/master/rpi-image-creator), and encounter some trouble with the kpartx use. The trouble ...
0
votes
1answer
35 views

Bash script to connect to Teletalk internet

I'm running Elementary OS(based on Ubuntu 12.04), and I have to connect to the internet in a peculiar style. I use a Teletalk modem to connect to the internet. Unfortunately, the modem gets recognized ...
4
votes
4answers
507 views

How to insert all lines from one file to another file?

File1: .tid.setnr := 1123 .tid.setnr := 3345 .tid.setnr := 5431 .tid.setnr := 89323 File2: .tid.info := 12 .tid.info := 3 .tid.info := 44 .tid.info := 60 Output file: .tid.info := 12 ...
1
vote
1answer
40 views

How can I execute and interrupt a script in a loop

I have a script called demo.py First I execute the script python demo.py -some arguments After some time (let say 120 seconds) I interrupt it with Ctrl+C and execute again. Can I write a bash ...