0
votes
2answers
29 views

Bash - Calculate the Average of Numbers Inputted

Need help with Linux Bash script. Essentially, when run the script asks for three sets of numbers from the user and then calculates the numbers inputted and finds the average. #!/bin/bash echo ...
0
votes
3answers
28 views

Linux using tar and if else when it has a file or not

I have a simple problem. I want that this script will say that if tar has a file inside "echo tar successful!" else "echo don't have any files". This is my script: stat -c"%z;%n" * | grep ...
0
votes
1answer
26 views

How could I copy a directory somewhere else (perhaps temp) and ensure it stays in sync with the original?

So I want to write a script that will allow me to temporary move some files/directories to a new location (perhaps temporarily or sometimes permanently) so that any changes made on the original or the ...
0
votes
1answer
33 views

Bash script not deleting files in given directory

I found this bash script online that I want to use to delete files older than 2 days: #!/bin/bash find /path/to/dir -type f -mtime +2 -exec rm {} \; I setup a cronjob to run the script (I set it a ...
0
votes
1answer
32 views

Logging into sudo in expect failing - BASH

Here is my expect script that a bash script calls on: 1 #!/usr/bin/expect -f 2 3 set timeout 1 4 set user [lindex $argv 0] 5 set pw [lindex $argv 1] 6 7 spawn ssh [email protected] ...
0
votes
2answers
35 views

not a valid identifier error with read command

I have looked into reading files from this site, man pages and google but not understanding, I apologize if this has been answered. I am having trouble reading a file into my script. I am using bash ...
0
votes
0answers
13 views

Formatting Text with Mutt

I am sending an email using mutt but i am not getting the text formatting i expect (specifically bolding some words in the body of my subject): /usr/bin/mutt -s "Subject" "[email protected]" ...
1
vote
3answers
33 views

Order text file by frequency of occrrences

Given a text file which will have duplicate lines in it such as: this is a line this is a line this is another line this is a line this is yet another line this is yet another line Is it possible ...
1
vote
1answer
37 views

Find cpu time of a process and it children while the process is still running

I have a bash script which runs a series of programs which run other programs . How would I get the cpu time of the bash script and all of it descendants processes. I looked in ...
4
votes
3answers
92 views

Outputs of “ls *” are inconsistent

Just confused about the outputs of command "ls *". I tested below scenario both in Ubuntu 11.10 and Redhat Enterprise 6.3, got the same results. Shell log $ uname -a Linux ...
1
vote
3answers
44 views

Confusion with the redirection of output to 2>&1?

I have checked couple of relevant posts regarding this in stackoverflow and other sources regarding the usage of 2>&1. Unfortunately so far have not get my head around it completely. I ...
3
votes
2answers
46 views

Why does output redirection not work in this case?

OS is ubuntu12.04. I wrote a python program main.py, and wanted to run it easily. So I created the following shell script called run.sh. #!/bin/bash python main.py & >/dev/null 2>&1 ...
1
vote
1answer
11 views

How do I get an output from Linux Top in Batch Mode on every iteration?

I'm trying to log CPU and Memory stats into a file by using top on an Arch Linux. I'm just interested in one specific process and get the wanted parameters as shown below: top -b -n1 -p 310 | tail ...
0
votes
1answer
29 views

multiple files from different directory as input to awk

I have different files with same file names and they are stored in different directories such as /path/to/2000/{a,b,c}.txt ... /path/to/2001/{a,b,c}.txt since I want to use variables to represent ...
0
votes
3answers
21 views

How to set a variable to current date and date-1 in linux?

I want to set the variable date-today to the current date, and date_dir to yesterday's date, both in the format yyyy-mm-dd. I am doing this: #!/bin/bash d=`date +%y%m%d%H%M%S` echo $d
-2
votes
2answers
41 views

Bash script, please help me to make it [on hold]

I want to make bash script... and the result : Row 1 : 1 2 3 4 5 6 7 8 9 10 Row 2 : 1 2 3 4 5 6 7 8 9 10 Row 3 : 1 2 3 4 5 6 7 8 9 10 Row 4 : 1 2 3 4 5 6 7 8 9 10 Row 5 : 1 2 3 4 5 6 7 8 9 10 ...
0
votes
1answer
33 views

Upgrade Mysql old password to new version [duplicate]

This probably has been asked before. Some passwords for the users are stored in 16 bit format. Mysql has been upgraded to 5.5, but the passwords in the table remained in a 16 bit format. A way to ...
1
vote
4answers
36 views

error occurs when executing the first row of linux bash scripts

We use notepad++ v6.4.5 to edit Bash scripts in Chinese Windows XP sp3. The coding format is UTF-8 without BOM. The first line source is as below: #!/bin/sh The source is executed on Centos 6.4 ...
1
vote
3answers
47 views

how to copy and rename file with for loop in bash script?

How I can copy all file *.html to *.php with For loop? help me... this my script : #!/bin/bash list="$(ls *.html)" for i in "$list" do newname=$(ls "$i" | sed -e 's/html/php/') cat beginfile ...
0
votes
3answers
37 views

Bash code executing before it should

I'm running some code on a remote server over ssh but when i try to execute code to save to the variable 'APP' it will run before mounting the file and also do that on the local machine instead of the ...
0
votes
2answers
33 views

edit ASCII value of a character in bash

I am trying to update the ASCII value of each character of a string array in bash on which I want to add 2 to the existing character ASCII value. Example: declare -a x =("j" "a" "f" "a" "r") I ...
-1
votes
1answer
35 views

bash - calculate process' time, i/o, cpu, memory usage [on hold]

I need a script which will start some process and calculate it's time of running, cpu usage, memory usage, hdd i/o usage in linux. System has 1 processor. Is that possible to determine that? Thank ...
1
vote
5answers
41 views

List the first few lines of every file in a directory

I'm trying to create a really simple bash script, which will list the first few lines of every file in a specific directory. The directory should be specified by the argument. I think that the Grep ...
-1
votes
1answer
38 views

Bash: back ticks character shielding strange behavior [on hold]

How does the following work? [crimsonlander@users ~]$ echo `echo 1\ 1` #1 1 1 [crimsonlander@users ~]$ echo `echo 1\\ 1` #2 1 1 [crimsonlander@users ~]$ echo `echo 1\\\ 1` #3 1\ 1 ...
-1
votes
0answers
23 views

What is CyberArk? How it is connected to Linux environment? [on hold]

I am trying to understand the functionality and the working of CyberArk as it is needed for a project. As for as I know CyberArk is a Safe just like a secured folder? I found some document here and ...
0
votes
1answer
23 views

Shell script not seeing files DEBIAN

I am using a shell script on My Debian 7 VPS, and it calls for 2 files to be in the Server Directory, (java.pid and screen.name). So I created them, and they have no text in them. I then get a error ...
4
votes
1answer
32 views

Bash: back quotes and eval confusing behavior

Can someone explain the second result? user$ set 5 5 user$ n=2 user$ eval echo \$$n 5 user$ echo `eval echo \$$n` 10268n 10268 is bash pid. GNU bash, version 4.0.35(0)-release ...
-3
votes
2answers
35 views

bash ping ip run command on reply

I would like to be able to check for ping replies to two different ip addresses and upon success execute a command. ie ping 8.8.8.8 on response do ping 8.8.4.4 on response execute command if ...
1
vote
1answer
42 views

Terminal giving “Unknown option on the command line: -gf” error with YouTube video streaming script using youtube-dl and mplayer

I have made a bash script where I can stream a YouTube video with youtube-dl and play it with mplayer. I based it on this terminal command: $ mplayer -ontop -cookies -cookies-file ./cookie.txt ...
0
votes
0answers
59 views

get the size and other info with the “du” command

I'm doing a little script on bash, which shows the total size in mb, the number of files, the number of the folder and the name of folder. I have almost everything except the size in mb du -a -h | ...
1
vote
2answers
38 views

Why a background process forces the parent to exit when background process exits with status 1?

My Bash code : #!/bin/sh set -ex function func () { sleep $1 echo $1 if [ $1 -eq 10 ]; then exit 1 fi } func 10 & pid_a=$! func 5 & pid_b=$! func 3 & pid_c=$! wait $pid_b if ...
0
votes
3answers
40 views

Capture the output of command line in a variable in Unix

I want to capture the output of the command below in a variable. Command: find . -iname 'FIL*'.TXT The output is : ./FILE1.TXT I want to capture './FILE1.TXT' into 'A' variable. But when I am ...
0
votes
1answer
20 views

script that returns list of global variables containing specified string

taking a linux 101 course using bash shell and have an assignment to creaet a script that: Lists all global variables that contain the string given in the command line argument. Do this using a pipe ...
0
votes
0answers
27 views

when should I use /sbin/halt instead of /sbin/shutdown? [on hold]

I know this question has been asked a lot of times, but I didn't find an answer that satisfied me. I'd like to know when is it useful to halt instead of poweroff. When would someone say, "hey dudes, ...
0
votes
0answers
17 views

how to create checksums while images are captured with gphoto2

I want to create an MD5 hash for each shot captured with gphoto2. I tried to run this command sudo gphoto2 -capture-image-and-download -force-overwrite \ -filename capture.jpg -I 10 && ...
2
votes
1answer
20 views

Using bash pipe instead of select statement

I was wondering if it is possible to use a bash pipe instead of a select statement on a tab seperated value(tsv) - file My tsv file has the following structure: CREATE TABLE movies (title VARCHAR, ...
-1
votes
3answers
43 views

Selecting specific values on script bash [on hold]

I need to get some informations from this string (df command) Filesystem Size Used Avail Use% Mounted on /dev/sda1 19G 3.8G 14G 22% / I need to get: The available space value And ...
0
votes
1answer
29 views

How to compress multiple folders, each into its own zip archive?

So I want to create a script that enables me to compresses each folder into its own zip archive and not into a one big zip file. As an example, I've got a directory: + MyDirectory/ | | | + ...
-1
votes
1answer
72 views

Awk vs Awk + cut vs. bash

We all know that there are always multiple ways to solve a problem. I was wondering what the upsides and downsides of each of the particular solutions in one case would be. Time- and space-wise (and ...
0
votes
1answer
45 views

Writing a script that copy files to sub folder

I need your help in writing a script(ubuntu-bash). suppose i have a folder in a certain name and i want to copy all the files in the folder to a sub-folder that starts with the first letter of the ...
0
votes
1answer
23 views

Linux command line issue with prompt

I started to manage a new server based on CentOS. I wanted to change the prompt, so I wrote the following command : PS1="\e[0;36m[`pwd`]\$\e[m " It worked perfectly. But since I got an annoying ...
0
votes
0answers
22 views

Nagios Unable to search for a Log File

I have written a simple Shell script for nagios.In the script i am tring to tail a particular file and grep out particular words and mach it with the words i know if the needed words are found it ...
1
vote
2answers
39 views

Find an xterm window by title, enter one command and press return using python/bash

I have an xterm window with a custom title. The xterm was fired up the following way: xterm -T customTitle. I would like to enter a command (for example ls -l) into this xterm window from a ...
1
vote
1answer
31 views

Permission error when using cat command as an editor [duplicate]

The following command works as expected: # Add/create /tmp/hosts with the string content inside EOFs $ cat >> /tmp/hosts <<EOF 127.0.0.0 example.com 127.0.0.0 foo.example.com EOF ...
1
vote
1answer
50 views

How can I change `grep '^2013-12-03'` to “2 days ago”?

I need to tar a file from 2 days ago, every day. This is my script: stat -c"%z;%n" * | \ grep '^2013-12-03' | \ grep "FPROD-LvL0-*" | \ awk -F';' '{ print $2 }' | \ xargs tar -zcvf pjpj_$(date ...
19
votes
6answers
42k views

wget with authentication [closed]

How can I download a webpage that require username e password ? For example I want to download this page after I have entered username e password: http://forum.ubuntu-it.org/index.php
130
votes
8answers
42k views

Pipe to/from Clipboard

Is it possible to pipe to/from the clipboard in bash? Whether it is piping to/from a device handle or using an auxiliary application, I can't find anything. For example, if /dev/clip was a device ...
103
votes
6answers
43k views

How do I write stderr to a file while using “tee” with a pipe?

I have the below command line argument which will print the output of aaa.sh to the screen while also writing stdout to bbb.out; however I would also like to write stderr to a file ccc.out. Any ...
515
votes
11answers
337k views

How do I tell if a file does not exist in bash?

I've used the following script to see if a file exists: #!/bin/bash FILE=$1 if [ -f $FILE ]; then echo "File $FILE exists." else echo "File $FILE does not exist." fi What's the correct ...
41
votes
10answers
34k views

How to copy a file to multiple directories using the gnu cp command

Is it possible to copy a single file to multiple directories using the cp command ? I tried the following , which did not work: cp file1 /foo/ /bar/ cp file1 {/foo/,/bar} I know it's possible ...

15 30 50 per page