bash

How to sudo on a computer using ssh inside a bash script

I'm trying to run a bash script that has: ssh -l <username> <compname> 'sudo yum -y install expect' I get the error: sudo: sorry, you must have a tty to run sudo on some computers but on others the process runs smooth. How can I prevent this? ...

Longest line in a file

I'm looking for a simple way to find the longest line in a file. Ideally, it would be a simple bash shell command instead of a script. ...

Bash egrep numbers not working in case

I'm reading a number from a file using x= egrep "(^[0-9][0-9])" temp1 but when I use these numbers in a case statement it always fails: case $x in [0-9]) statements;; [0-9][0-9] statements;; esac when I echo the number it looks fine, I'm not sure why it is not working. ...

Controlling rsync with Python?

I've been wanting to write a python script that would run several instances of rsync in sequence for backing up data to a different computer. At the moment I just have this text file with the commands I use and I've just been copy-pasting them into the terminal, and it seems kinda silly. I want to be able to use python to do this for m...

Bash Menu: Return to menu after selection made and executed?

Hi folks. I've got a bash script that writes to a file. at the end of the script I want to display a menu, with line numbers - and have the user be able to select 1 or 2, (etc. up to the number of lines in the file) then have it execute that line. Up to here is perfect. However, after the line is executed (say for example it displays...

Comparing strings for equality in ksh

Hello, i am testing with the shell script below: #!/bin/ksh -x instance=`echo $1 | cut -d= -f2` if [ $instance == "ALL" ] then echo "strings matched \n" fi It's giving this error in the if condition: : ==: unknown test operator is == really not the correct syntax to use? I am running on the command line as below test_lsn_2 INST...

Shell script sort list

I have a list with the following content: VIP NAME DATE ARRIVE_TIME FLIGHT_TIME 1 USER1 11-02 20.00 21.00 3 USER2 11-02 20.45 21.45 4 USER2 11-03 20.00 21.30 2 USER1 11-04 17.20 19.10 I want to sort this and similar lists with a shell script. The result should be a new list with lines that do not collide....

tomcat startup script permission on mac os x

hello people i'm struggling with a mac os x 10.5.8 that i've started using recently for development.i successfully installed tomcat and create launchd.conf for my environment variables.i believe it works fine.coz i can build a project with netbeans using maven and cargo plugins succesfully so i found online a script for start and stop t...

A script to ssh into a remote folder and check all files?

I have a public/private key pair set up so I can ssh to a remote server without having to log in. I'm trying to write a shell script that will list all the folders in a particular directory on the remote server. My question is: how do I specify the remote location? Here's what I've got: #!/bin/bash for file in [email protected]:dir/*...

How do I fix this sed problem with unterminated lines?

I'm guessing this has to be an escaping issue, but I can't find it. What's most frustrating is that this is based on an old sed script I used that worked, so why can't I make it work when I try to re-use it a year later? ;) Framework: I have a file with a list of filenames in it that all need the same string of HTML searched and repla...

mysql create database and user script

Question Rewritten: HOMEDIR="ftpuser" REMOTEIP="1.1.1.1" MYSQLPASS="password" Q1="DROP USER "$HOMEDIR"_shop;" Q2="DROP DATABASE "$HOMEDIR"_shop;" Q3="CREATE DATABASE IF NOT EXISTS "$HOMEDIR"_shop;" Q4="GRANT ALL ON "$HOMEDIR"_shop TO '"$HOMEDIR"_shop'@'localhost' IDENTIFIED BY '$MYSQLPASS';" Q5="GRANT ALL ON "$HOMEDIR"_shop TO '"$HOMED...

Is it possible to have Perl run shell script aliases?

Is it possible to have a Perl script run shell aliases? I am running into a situation where we've got a Perl module I don't have access to modify and one of the things it does is logs into multiple servers via SSH to run some commands remotely. Sadly some of the systems (which I also don't have access to modify) have a buggy SSH server t...

Bash Script to find the most recently modified file

Hi, I have two folders, for arguments sake /Volumes/A and /Volumes/B. They are mounted network shares from a Windows server containing a load of .bkf files from Backup Exec. I am looking for a script which will look into both folders and find the most recently modified .bkf file and copy it to another location. There are other files in...

How to keep quotes in args?

I have a bash script where I want to keep quotes in the arguments passed. Example: ./test.sh this is "some test" then I want to use those arguments, and re-use them, including quotes and quotes around the whole argument list I tried using \"$@\", but that removes the quotes inside the list. How do I accomplish this ? ...

How to sort by line length, then reverse alphabetically

I have a large (600 odd) set of search and replace terms that I need to run as a sed script over some files. The problem is that the search terms are NOT orthogonal... but I think I can get away with it by sorting by line length (i.e. pull out the longest matches first, and then alphabetically within each length. So given an unsort set o...

How can I control inputs on Shell Script?

Hi I am getting parameters from user ./inputControl.sh param1 param2 ... I want users can only enter numbers. can not enter any words, etc. if they enter word i will show them error. thanks for answers ...

Indenting Bash Script Output

Hello all, I am attempting to write a bash script and I am having difficulty making the output look neat and organized. I could fall back on just using newlines, but I would much rather have output that was easy to read. For instance, when I run git clone ..., I want to first echo "Cloning repository" and then have the output of git ind...

Accessing SSH key from bash script running via a cron job

I've put this script together to updated a folder of forked Github repositories on a daily basis. It runs fine if I call it from a prompt, but I can' figure out how to make it utilize my id_rsa reliably when it is run as a cron job. the eval 'ssh-agent' is an attempt to do just that, but it doesn't seen to have any positive affect. #!/b...

Security or other gotcahs in Apache-CGI-Bash application?

I've taken over supporting a time- and expense-entry system. Apache's CGI. CGI programs are written in bash :) I'm going to add some features into it and exposing it out to many more users, but prior to that wanted to get some thoughts on what else needs to be looked-at first in terms of security, holes, CGI gotchas, &c. Not a lot of...

How to read out vendor ID of CF-Card

Hello I'm writing a bash script which fills cf cards with an image. Since only specified cards are allowed, I'd like to check if the right type of cf card is plugged in the USB cf card writer. I know that it is possible to read out vendor id and firmware version of the cf card somehow (I saw it on an embedded system), but I don't know ...