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

learn more… | top users | synonyms (2)

0
votes
1answer
51 views

sftp to use password stored in a parameter file

Is it possible to to connect two server through sftp with a batch of commands and where the authenticating password needs to be read from a file(where it is stored previously).I am new in UNIX world , ...
0
votes
1answer
9 views

Command Run Differently Depending on How Logged In?

Is there a way to have one command run differently, depending on the manner in which one is logged into the session launching it? Basically, we have a command that when run, launches vim to display ...
1
vote
2answers
47 views

Returning an variable from a function

I have the Linux script from bellow. I can get to return from the method decrypt nothing in order to unzip a file. The method decrypt sends a string with the name of a zip file. Please give some ...
1
vote
3answers
42 views

How can I un-write protect file made by tee?

I have a small program and I want to ensure that it works on both write protected files and un-write protected files. So, instead of using echo $text > $file or echo $text >> $file, I am ...
-8
votes
1answer
60 views

replace the the first line of all .sh files in a folder

Create list of all .sh files in current folder. Check first line of each file in this list and if file starts with #!/bin/sh then replace that with #!/bin/bash. Only modify files that have #!/bin/sh, ...
-5
votes
1answer
61 views

Find the number of files with sizes

Find the number of files with sizes > 100KB in /, /bin, /usr, /usr/bin and /usr/sbin directories and output them in a two column format with the name of the directory and the number of files.
1
vote
3answers
40 views

permissions of script to change permissions?

I have a VMWare VM that directly accesses some disks. In order to run (without running vmware as su which has its own problems) I need to change the ownership of the devices. I've done this manually ...
0
votes
0answers
5 views

Find MAPISend syntax and Replace with BLAT syntax

My MAPISend code seems to have kicked the bucket so now I am trying to replace over 1,500 MAPISend lines with BLAT. Is there a way to search through my scripts and find the MAPISend syntax: ...
2
votes
2answers
37 views

Embed “cat file” in CURL data

I would like to cat the contents of a file.txt and use this as part of the --data field in my curl query. I tried: curl ... --data '{ "file_content":[" $(cat file.txt) ", ...]}"' ... but that ...
0
votes
0answers
27 views

Shell script to execute python scripts. Look at errors that are raised/specific contents of print statements [closed]

I wish to run a python script in a variety of different ways, enumerating errors and monitoring the kinds of issues that could crop up. Is there any way to 'count' the number of errors/print ...
-3
votes
0answers
19 views

bash script to display,add and delete data in a txt file(txt file is created seperately) [closed]

A script through which we can add,delete,display data(s) of a txt file created separately. The use should be like ./MY_SCRIPT -add [ID] -delete[ID] etc.
1
vote
2answers
101 views

Execute CURL command only once in script?

To explain a little, I am currently monitoring a folder for any changes and when changes are detected it simply uploads the detected files to my server via rsync. This is working without any issues : ...
1
vote
2answers
37 views

Else not Executing

In my script, I transform data to a more readable format. But I am having an issue. If no arguments are typed, just the script, I want it to come back "Please enter a filename" which I have done. But ...
1
vote
2answers
59 views

where I can modify the below shell script?

This is my input: #!/bin/bash #Example of menu programs clear echo "*******************" echo "1.Date" echo "2.List of users" echo "3.Open a file" echo "4.delete a file" echo "5.Exit" echo "Enter a ...
0
votes
0answers
17 views

What does a hash key preceded by an exclamation key (!#)mean? [migrated]

See the following script from scala tutorial, What does the !# mean? #!/bin/sh exec scala "$0" "$@" !# object HelloWorld extends App { println("Hello, world!") } HelloWorld.main(args)
1
vote
2answers
103 views

Remove lines from CSV file if the second column is in a word list

I have found a long list of free email providers that I want to remove from my email lists - https://gist.github.com/tbrianjones/5992856 Below are two commands I currently use that do the same job ...
3
votes
1answer
42 views

Generate a large number of the same byte [duplicate]

I'm generating a binary file as test data for a piece of software. The test data should consist of a long array of the same byte. If it was a zero byte I would use /dev/zero. Is there a command to ...
1
vote
3answers
51 views

script for copying directories with particular increment

I have directories which are named as 0.1, 0.15,0.2, 0.25, 0.3,0.35 and so on. Now I want to copy directories at particular increments say of 0.1 together to a separate directory. Say directories ...
0
votes
2answers
67 views

Shell Script: Sending input to background process

I am using the following script to watch a folder, and if the size changes and a file doesn't exist, it runs a script. #!/usr/bin/sh SCRIPT="dim_import/xdir" while true; do size=$(du -s ...
0
votes
1answer
17 views

Determine the tmux session a shell session belongs to?

tmux provides a number of commands in the shell such as rename-session which operate on the session that the invoking shell belongs to. It also provides commands like list-clients which list out the ...
0
votes
3answers
78 views

How to rename all files with special characters and spaces in a directory?

How can i rename all the files in a specific directory where the files contains blanks spaces and special characters ($ and @) in their names? I tried the rename command as follows to replace all the ...
1
vote
4answers
47 views

How to move all files (excluding sub-directories) from one directory to another?

How do you move all the files (excluding sub-directories) from one directory to another. I'd prefer if the solution used just basic shell scripting.
2
votes
1answer
50 views

SSH command not exiting properly [closed]

I wrote a script that SSH to remote servers in loop and run a command, it gets hung after running on last server.Here is my loop script - cat server | while read serName do ...
1
vote
1answer
54 views

How to make awk work in a while loop

input.txt: /usr/dir1/file1 /usr/dir1/file2 /usr/dir2/file4 /usr/dir3/file5 Script: cat input.txt |while read FILENAME do nawk '{print $1}' ${FILENAME} >> output.txt done Expected output: all ...
0
votes
1answer
61 views

load bash comands from file one per line and execute them for each file in a directory

I'm trying to write a bash queue which will be able to load command set from a file and then execute each over set of files. prepared file should serve as a template for execution in manual bash ...
3
votes
1answer
39 views

Condition on finding a file

I'm trying to write a script which looks for a file and if it is found, saves the full path to a variable. Current version: if [[ -n FOUND_PATH=$(find "$PATH" -name "file.exe") ]]; then echo ...
0
votes
0answers
15 views

Accessing HTML pages through command line for scripting [duplicate]

There is a web page that I usually do the same thing over and over on. Click a button, enter some text and that's it. Is there any program that allows me to interface with a webpage with a couple of ...
3
votes
2answers
30 views

Setting variable with default value behaves differently when preceding a command?

Setting a variable with a fallback default value works...as long as we're using the variable in a subsequent command: $ unset APP_ENV $ echo $APP_ENV $ APP_ENV="${APP_ENV:-production}"; echo ...
1
vote
2answers
45 views

Remove x lines before and y lines after nth line (which matches a pattern) in a file

I'm trying to remove a four line block from a text file if the second line matches the Regex N+. The text file is composed of many repeating 4 line formats, ie: @HEADER1 ACTGCNNNT + 583@#!NMY ...
0
votes
4answers
53 views

Excluding specifics lines from being redirected [closed]

Let's say I am executing a script like this : /a/b/c/script.sh >> abc.log This will mean that all the contents/execution of script will be re-directed to abc.log. If I want a particular line ...
0
votes
1answer
30 views

Redirect stdin for multiple shell functions [closed]

I'm surprised nobody has asked this before - maybe I'm just that dumb? How to I force this script to do what I intended? #!/bin/bash function One() { IFS='' read -r -n1 CHAR echo "One: '$CHAR'" ...
0
votes
1answer
30 views

Calculate swap values dynamically

Can someone please let me know if the below should work as i am not sure and getting error? Just to let you know that i am using in one of my nagios script ## GET SWAP Warning and Critical values ...
2
votes
2answers
42 views

How to make this loop Ctrl+C-interruptible?

# wait for host to become online while true; do ping host -c 1 -w 3 > /dev/null && break; sleep 1 done When I press Ctrl+C, the ping receives it and exits with exit code 1 (the ...
0
votes
3answers
55 views

Best way to obfuscate aix script

What is the best way to obfuscate shell script in aix? The problem is that is a shared user and I would like to the other don't know the code.
1
vote
3answers
66 views

Random sampling and outputting the largest value

I have a fairly large data set ~500 million rows. The data set looks like below. Col 1 is float number, col 2 is mac id(device id) 1616.93,ac:22:0b:a6:22:c3 2872.32,c0:bd:d1:36:bb:49 ...
1
vote
2answers
50 views

Matching “keyword value” pairs from semi-structured input

On occasion I get output from a command that includes "key value" pairs, with possibly more than one pair per line. As a repeatable example, consider the command ip addr show dev eth0: ip addr show ...
1
vote
1answer
57 views

How can i use multiple if statement inside another if statement of a awk program?

I have a CSV File and i want to have multiple checks to retrieve the data from the CSV file. I have the following conditions which needs to be taken care of and i am trying to use awk in a shell ...
0
votes
2answers
55 views

Telnet check in bash script

I want to run following commands in bash script form in Solaris 10: $ telnet localhost 25 debug quit How I handle this?
1
vote
1answer
32 views

bash ignorecase match pattern in file and color that line, print all to screen

I have almost zero idea about coding or bash scripting, so please bare with me and excuse my horrible formatting. What I want is to cat a log file and highlight certain lines with color based on a ...
10
votes
3answers
740 views

What's a smart way to count the number of days since X?

I started working at my current position since November 17th 2014. I would like to know how many days have run up to now. Any ideas on how to use Linux to come up with a simple and nice solution ?
0
votes
1answer
18 views

Setting arguments from a text file does not work

Here is my code. #!/bin/bash set -- $(cat /home/jeevan/tempzen1.txt) zenity "$@" file tempzen1.txt contains : --list --title FILE-SELECTOR --column serialno. --column file --width 1000 ...
1
vote
4answers
72 views

Problem with entire function in a script

I want to detect online network/shell services in my Solaris. I write following script for this purpose: compare_ser() { if [ "$1" != "" ]; then echo "True" >> Solaris.txt fi } export -f ...
1
vote
1answer
67 views

How to select rows from a CSV file based on different column values?

I have a CSV file with values like the following: col1,col2,col3,col4,col5,col6,col7 1,0,0,0,0,BTS,Active 4,5,3,1,1,LocalMode,Offlne 1,2,5,6,3,PermFault,Offline 1,2,6,6,2,BSC,Active ...
1
vote
2answers
35 views

Something wrong with spaces in zenity trying in a script [duplicate]

While this is directly executed in terminal it works fine zenity --info --text "pure info" --title "get info" But this script doen't work what's wrong? !/bin/bash ZEN="--info --text \"pure info\" ...
-1
votes
0answers
23 views

Script for checking OU/OC trend for last few FGC cycles

I have a script in place which sends alerts regarding cluster memory utilization and some other info. My issue is that for some clusters the memory utilization(in % age) trend has to be checked at ...
4
votes
3answers
146 views

Bash script: do something one time inside a loop then stop, but continue looping

I have a Bash script that checks my laptop battery and sends me an Android notification (via shuttle, a Bash script I wrote that serves as a cli interface for the Pushbullet API). It works nicely, but ...
3
votes
2answers
47 views

Create thumbnail from video at random time frame

I'm using this bash script to generate thumbnails from videos: #!/bin/bash source_dir="." output_dir="/output" input_file_types=(avi wmv flv mkv mpg mp4) output_file_type="jpg" r1=$(( ( RANDOM % 10 ) ...
1
vote
2answers
62 views

how to store output of a command into array with each value in a double quote

I want to store each output in double quoted array values. values can have space also. FOUNDFILES=($(locate --database ~/.locate.db -i -b "$INPUT")) if input to the locate command is very very ...
1
vote
1answer
35 views

How to parse a CSV file based with groups made of specific number of rows?

I have a CSV file which has the following format: Date,Towns,Count1,Count2 6/26/2015,HYDERABAD,234552,0 ,KARIM NAGAR,7520,0 ,RAJAMUNDRY,7248,256 ,KURNOOL,5848,32,0 ...
10
votes
3answers
406 views

Date validation in shell

I want to validate the below date format in shell script 2015-Jul-13 I'm using date -d "2015-Jul-13" +"%Y-%b-%d" but its giving error as date: invalid date '2015-Jul-13'