Count number of files in remote server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count number of files in remote server
# 1  
Old 02-03-2012
Count number of files in remote server

Conneect remote server and then count no of files in the directory
Code:
 sftp ksmsft1@laixu110.jkea.jlroot.net << EOF cd /opt/jls/  ls quit EOF

When I try above command it doesnt work , we have ssh configured and hence with below command I can connect without asking for password
I have two imp requiremenss
1)Connect and count no of files in a directory as
Code:
 ls -lrt | wc -l

will not work in sftp prompt
2)need this code in one line as I am executing it from some other application
In case there is other easier way please let me know
# 2  
Old 02-03-2012
Why sftp ?? and why not ssh ..
Code:
$ ssh ksmsft1@laixu110.jkea.jlroot.net "ls -ltr /opt/jls | wc -l"

# 3  
Old 02-03-2012
cant use ssh

as it gives message "No terminal authorization granted"

Last edited by lalitpct; 02-03-2012 at 05:45 AM.. Reason: correction
# 4  
Old 02-03-2012
Are you getting the required output along with this message?
Use -q to suppress such messages.

--ahamed
# 5  
Old 02-03-2012
nope it doesnt give output as well
# 6  
Old 02-03-2012
What do you get for this?
Code:
ssh ksmsft1@laixu110.jkea.jlroot.net "echo 1234"

Please paste the exact output you are getting.

--ahamed
# 7  
Old 02-03-2012
Code:
ssh ksmsft1@laixu110.jkea.jlroot.net "echo 1234"

** RESTRICTED ACCESS **
You are authorized to use this system for approved business purposes only. Use for any other purpose is prohibited. All transaction reports, reports, email, software, and other data generated by or residing upon this system are the property of the Company and may be used by the Company for any purpose.
Authorized and unauthorized activities may be monitored.
Received disconnect from 195.157.242.145: 2: No terminal authorization granted

---------- Post updated at 06:22 AM ---------- Previous update was at 05:43 AM ----------

Not sure if this helps but below command works absoultely fine
Code:
scp -r ksmsft1@laixu110.jkea.jlroot.net:/opt/jls/ /opt/kls


Last edited by methyl; 02-03-2012 at 09:03 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies

2. Shell Programming and Scripting

Help for Count number of files in certain time

Chaps, I need to count number of files in a remote directory from Linux (FreeBSD) as if 10 trace files (log files) been generated within 5min of time. So this is the script then I can setup a monitoring. I came across with ls -1 \ip\d:\Logs | wc -l but then what else requires to check time... (8 Replies)
Discussion started by: samwijekoon
8 Replies

3. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

4. Shell Programming and Scripting

Count number of files

Hi All! I need to have a script that counts the number of files arriving in a landing directory, them some app pick these files to be processed and load to a DB. But this process is so fast that I am not able to count all the files arriving on a landing directory. Please can you help? My... (6 Replies)
Discussion started by: fretagi
6 Replies

5. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

6. Shell Programming and Scripting

count of files and number of bytes

1) I need a shell code to count the number of files ( without directories or sub-directories ) in a directory given as arguments I tried this code but it didn't work , maybe I tried the wrong one: numOfFiles=`find $1 -type f -maxdepth 1 | wc -l` I found it in another thread in this site.. ... (17 Replies)
Discussion started by: jack1985
17 Replies

7. UNIX for Dummies Questions & Answers

Count number of files in directory excluding existing files

Hi, Please let me know how to find out number of files in a directory excluding existing files..The existing file format will be unknown..each time.. Thanks (3 Replies)
Discussion started by: ammu
3 Replies

8. Shell Programming and Scripting

Need to get specified number of files from remote server

Hi All, I need to get a specified number of files from a remote server. The remote server has a huge number of files to the tune of more than 200000. If I use scp or rsync to transfer files using the wildcard "*", am getting the error "arg list too long" So, I would like to know if i can... (2 Replies)
Discussion started by: umavmishra
2 Replies

9. Shell Programming and Scripting

count number of files in a directory

what's the script to do that? i want to only count the number of files in that directory, not including any sub directories at all (5 Replies)
Discussion started by: finalight
5 Replies

10. Shell Programming and Scripting

Count the number of files in a directory

Hi All, How do i find out the number of files in a directory using unix command ? (14 Replies)
Discussion started by: Raynon
14 Replies
Login or Register to Ask a Question