Today I have finally made up my mind to quit bat scripting and go for powershell... I need to do a quick script bascially trying to looping through a command output.. can anyone shed some light?

i tried

foreach ($col in 'app-command -argument')
    { echo $col }

well, guess my guess isn't correct. Can anyone help me with this? Thanks thanks

I udnerstand that setting up a public/private key authentication is a way to go when automating scp copy files to target machines.

however, I just now just to get a quick a dirty way to copy a number of files to a number of remote machines. My question is how to do that in a script?

I tried a couple attempts but haven't been sucessfully yet.

#!/bin/bash
echo "password" | scp source user@destination:\folder 

hope anyone can shed some light. Thanks much.

haven't been using linux for a while. remember I used to do search and replace all the time with :s/searchString/replaceString/g

now I have "pattern not found: " even though pattern I was trying to search/replace was definitly there.

any idea? did i forget anything?

stupid me.. i have to specify //192.168.xx.xx/epscan

thanks rubberman.

I normally mount my windows share as follow:

[code]mount -t cifs //192.xxx.x.xx/share -o username="username' password="pass" /mnt/mountPoint
[/code]

now I am trying to mount my epson scanner which has a SD card that can be shared on the network.

I did the same command but it failed to mount. pinging the device is fine. My epson share doesn't have a username or password.

Can anyone suggest any command to try?

Yes, I tried fully qualified. This is really puzzling me. This vm is in the lab, environment is generally not as stable as our production network.

It doesn't look like we have the same problem for production servers. I just don't like mystery. Weird = /

firewall are both off
dns server looks fine
both server can ping each other by hostname
both server use the same dns server
i ensured that they both use dns rather than win
what else to troubleshoot???

I am testing an open source application.

When at the setup stage after installing mysql, php all the good stuffs, I have to specify where the mysql server is. Here is the problem, if I put in "localhost" as the mysql is installed on the same box, it would work perfectly fine. If I put the actual hostname then it would fail.

pinging the hostname actually has no problem. The box is using a working dns server.

Did anyone experience any similar name resolving issue while ping, nslookup everything is workig but an application isn't able to see its hostname?

sorry, but it doesn't look correct still....

[code]
[root@itoplinux m]# cat file

!/bin/sh

Answ=""
b=0
c=1
d=2

Answ=""
Answ=""
dfjsl
Answ=""
dk
df23
Answ=""
z=0
=2
Answ=""
[root@itoplinux m]# sed -n '/Answ=""/,/z=0/p' file
Answ=""
b=0
c=1
d=2

Answ=""
Answ=""
dfjsl
Answ=""
dk
df23
Answ=""
z=0
Answ=""
[root@itoplinux m]#
[/code]

it looks like for some reasons [code]'/#modify/,/hi()/'[/code] doesn't do what it supposed to do.

if I have the below text, [code]'/#modify/,/hi()/'[/code] will find all the hi() in the text... im using bash 4.1.2(1) and sed 4.2.1 ... don't really think it matters though.. = /

modify

hi()
123
hi()
1354
hi()
tthi()
dskf
jsdf
jsdkf
hi()

i googled around, found some source vaguely explain about sed '/pattern/,/pattern2/'.. can't find anything certainly tells me this will search 2 consecutive line for match though.

Well, let's assume the combination of 2 lines below is unique

modify only the hi() below this line

hi()

Then "hi" will be the only hi() in return of the match. Then why do I still need the carat to specify it is at beginning of the line? By the way, all the hi() in my example text starts at beginning of line though.

I am just trying to understand if the ^ has anything to do with the multiple line match. Would sed '/match1/,/match2' matches "match1" on a line first and then check if "match2" is found on the line below? Sorry, it is hard without understanding its behavior for me.
[code]sed '/#modify/,/hi()/ [/code] will find the

this is another idea I have but not sure if it is doable...

what I am trying to ask is if there is anyway to modify x line number above or below a matched line.

example:
I know I am able to find a unique line "#this is a comment x"
I want to modify 3 lines down to make it "#this is a newly replaced line" no matter what this line is.
[code]

this is a comment x --> go down 3 line and make it "#this is a newly replaced ln"

line 1
line 2
line 3 --> i am hoping if there is a way that I don't have to care what this line is, as long as it is 3 line down from the matched line, then it will be replaced.
[/code]

I couldn't google anything close... thanks, maybe I should focus on the other thread on how to match patten of 2 lines.

[code] sed '/#modify/,/hi()/ {s/^hi()/hi(20)/}' [/code]
May I ask what does {s/[COLOR="Red"]^[/COLOR]hi()/hi(20)/} the carat do?

It actually matches and replaces all the hi() if it starts at the beginning of the line

Sometimes it is hard to locate the exact line you want to modify if there are so many lines having the exact same codes/text.

example:

this is x

a=0

this is y
this is yy

a=0
this is z
a=0

My question is, is it possible to find something unique, such as "#this is y" from above, and then modify the "a=0" 2 lines down?

this has been puzzling me..

thanks

one problem is that it will modify all the ^hi() to hi(20) instead of modifying only line 6 hi() I need. it doesn't look like the 2 line matching works.. = (

never mind, my bad that i forgot to redirect it to a new file. still not sure about matching more than 2 lines.

by the way, can I match more than 2 lines?

[code]sed '/line1/,/line2/,/line3/ s/^line2/line2change/' [/code]

something like this?

sed '/#modify/,/hi()/ s/^hi()/hi(20)/' tmp.txt

ummm, you did gave me some good hints. however, the shell complains about the " , "
maybe syntax is a bit off?

Say like I have hi() everywhere in a shell script and I would like to replace only a hi() to hi(20) right under the line "#modify only the hi() below this line".

Is there anyway that I can locate the line "#modify only the hi() below this line" and then do a replacement on the line right under the cursor?

example:
[code]

!/bin/sh

hi()
some other code

modify only the hi() below this line

hi() [B]---> this is the hi() i want to modify[/B]
hi()
other code
hi()
other code
hi()
[/code]

or if there is any other better approach? thanks

Gromit,
Thanks for your reply but yea, you were absolutely right. I resolved it by using RSA. I actually had done it before, it is just I haven't used linux for a while and I had to kinda learn things again. = )
Thanks and I am all set.

uh.. sorry for the confusion but i just figured that if the code is exectued outside the script it works fine.

putting the same code in a script it will prompt for password. scratching my head now.

actually, it does work.. it is just when putting in a for loop then it starts asking for password again.

[code]
pass=$1
for i in $(cat file)
do
echo "$pass" | scp --stdin source destination
done
[/code]

Im trying to scp including password in one line... seems not working.

[code] echo "pass" | scp --stdin source destination [/code]

However this does work though
[code]echo "newpass" | passwd --stdin user [/code]

same concept, diff result. Any suggestion would be great. Thanks

this is perfectly fine. It will grep each of the output, if it != "client" or "-----" then it will be written to the text file.

for /F "tokens=3" %%a in ('E:\things\bpplclients') do (    
        if /I not "%%a" == "Client" (
       if /I not "%%a" == "--------------" (
            echo %%a >> %userprofile%\desktop\clientInfo.txt   

however...

for /F "tokens=3" %%a in ('E:\things\bpplclients') do ( 
        set hn="%%a"   
        if /I not "%hn%" == "Client" (
       if /I not "%hn%" == "--------------" (
            echo %hn% >> %userprofile%\desktop\clientInfo.txt   
                                         )
                                 )

This will output "" instead of the value of variable %hn%...

How do i correctly set variable and be able to use the variable at a latter time. I wish it is as straight forward as bash or any other languages....

I have just installed (binary install) php 5.3.6 to my redhat box. However, it is still seeing a 2.x version. Does anyone know how to find out where my 2.x version is and possibly uninstalling it?

And how do I make mysql to use my new 5.3.6 version? Thanks. I am so confused about php conf files.

Does anyone know how to use awk to print every 3rd line from the 1st line and including the 1st line?

1st
..
3rd
..
..
3rd
..
..
3rd

soemthing like this?

the closest I could get was below, but it dosn't go beyond the 3rd line.. any ideas? or sed maybe?
[code]awk 'NR%3==1' file.txt [/code]

yes, CIFS is really handy (just tried a couple of win sharing)..
I also found out from someone that Win2008 is now supporting NFS.. I haven't looked into NFS much but I know NFS used to be for Unix and Linux. Does anyone know the diff between NFS and CIFS? Sharing a folder on windows would be cifs,, sharing the whole drive is cifs i think.. then what is nfs? is it just a diff protocol which does the same thing?

Would anyone please explain a bit about sharing between Unix and Windows?

From my understanding, Unix can only see windows's share/print by Samba. However, I was googling around and found many pages talking about mounting Windows CIFS by just using regular "mount" command. Is Samba outdated now?

Is it right that NFS (network file system) is for Unix while CIFS is for Windows? Can the terms be interchangable?

If I have created a Windows share folder, is this folder considered NFS or CIFS? What would be the easiest way to access this folder from Unix?

What about mounting a Windows box's CDRom?

Thanks

i am trying to export display to my xp box from redhat.. problematic again.

These are what I already have done:
on redhat:

export $DISPLAY=:0.0
export $DISPLAY=XXX.XXX.XX.XX ## my xp box ip
echo $DISPLAY
XXX.XXX.XX.XX
xhost +

xhost: unable to open display "xxx.xxx.xx.xx"

on xp:
installed xming x11 server and it is running

on putty:

under SSH, X11, X11, checked box "Enable x11 forwarding" X display location [xp box ip]

Is there anything else I missed? I think I have configured it the same way last time I made a Redhat box worked. Thanks

anyway, solved. use absolute path for everything not working.

another update for those of you interested in this...

if you have a win2008 box you may try this.

do a simple script as follow (you need to create a hi.txt file with some content)
[code]
type hi.txt > output.txt
[/code]

if you double clicked on the script it will run fine.
if you right click and run as admin, the script will be broken with the message saying "The system cannot find the file specified"