i have a short script that takes a filename and secure copies the file to a remote machine. i'd like to be able to take a * character and secure copy all the files in the directory.
first of all, how would i compare $1 to see if it's a * character?
if [ $1 = '*' ] or [ $1 = '\*' ] didn't do it.
second question is how would i tell the shell script to do 'scp * user@<ip>:/'? or do i have to do it one by one in a loop?
When you run your script you gotta do:
./yourscript \*
if you just do
./yourscript *
the shell will replace * with a list of filenames before your script even runs.
i have a short script that takes a filename and secure copies the file to a remote machine. i'd like to be able to take a * character and secure copy all the files in the directory.
It sounds to me like you're trying to do the work that the shell already does for you.
Say I cd to /tmp and do ls * . Say it comes back with file1 file2 file3
Then I create a script in my home directory. Call it foo. Now I cd to /tmp, run the command foo, with * as an argument: ~/foo * . Note that the script "foo" is NOT given a * as an argument. Because what the shell does, before it even executes the command (which is my shell script), is to: Expand variables, Expand metacharacters, and Expand commands in backticks (or $( ...) in ksh ). So when I type
, the shell does not run
. It expands the *, and really runs
.
So what you're thinking of doing is actually
I don't believe you need or want a directory in the "user@ip:" part of the scp because your files will by default be placed in the home directory of user over at your host given by ip.
Finally, I'm not sure of the syntax of the scp command with multiple files. Try doing two of them first, and see if it works. Remember that metacharacters aren't magic, they are pretty ignorant although powerful. What they do is serve as placeholders for a replacement. The shell does the replacing, then and only then does your script or command get the results of the replacement(s).
-mschwage
Sorry I put -r I ment to out -w but its not perform none of -w, -r, -x flags
Using centos 6.4
#!/bin/bash
echo -e "enter the name of file :\c"
read file_name
if
then
if
then
echo "Type some text date. Tp quit press crtl-"
cat >> $file_name
... (2 Replies)
Hi,
I need to know what are the storages attached to some of our corporate servers. I run this command from the server only to get a list of WWNs :
# /usr/local/bin/evainfo -a
Devicefile Array WWNN Capacity ... (1 Reply)
Hello,
I re-installed my laptop and installed a new copy of VMBOX, I created a VM Machine with my Rhel5 and a CEntos copy as well.
I am using a laptop HP DV4, I use wireless on the laptop.
Usually when I boot up in to either machine I would get eht0 and lo as usual now I just don't get... (4 Replies)
Hello,
I've read many posts that offer tips on how to mount a CDROM but I haven't seen any on how to get the system to recognize the CDROM drive.
I was transferring files from CDROM to the hard drive successfully. I entered the third CDROM and the system refused to automount it. I tried... (2 Replies)
I thought I posted this before, but cannot see the post, so will re-post.
Apologies if it now appears twice !
My script prompts for a 7 digit parameter : read f1
I then run a find command to search for files with $f1 in its contents :
find . -print | grep $f1 {file} > temp1
I then run a cut... (1 Reply)
I've just installed Sol 10 Update 9 on a Sun 4140 server and have a RAID 1 configuration (2 136 Gb drives) for the OS and have created a RAID 5 array (6 136 GB) drives. When i log into the system I am unable to see the RAID 5 disks at all. I've tried using the devfsadm command but no luck and... (9 Replies)
I will be passing an argument to a csh script
The script can be either of two forms
For example, either
script.csh zloc=5/10
or
script.csh zloc=5/10/20
So there can be either two values or three values. How can I distinguish which one the user has inputted?
I have made... (1 Reply)
Hi All,
I am using crontab which execute a shell script.
In the shell script, I am executing a java program. This Java program requires the jar files.
The cron job file ' cronfile.txt ' contents:
MAILTO="raju_utla@dcis.uohyd.ernet.in"
0-59 * * * *... (4 Replies)
Hi All,
I am using crontab which execute a shell script.
In the shell script, I am executing a java program. This Java program requires the jar files.
The cron job file ' cronfile.txt ' contents:
MAILTO="raju_utla@dcis.uohyd.ernet.in"
0-59 * * * *... (0 Replies)
hi folks,
I am trying to write a script for deleting all the files which are older than "N" days from current directory.
CODE:
FileName="*.*"
NumDays=-1
echo $FileName
echo $NumDays
find * -prune -name $FileName -mtime $NumDays -exec rm {} \;
Now the problem here is when i... (3 Replies)