Sponsored Content
Full Discussion: Query on scp
Top Forums UNIX for Beginners Questions & Answers Query on scp Post 303000877 by rbatte1 on Friday 21st of July 2017 12:32:07 PM
Old 07-21-2017
Having got the files, would a loop using stat and it's various flags be suitable? You don't tell us you OS, so I'm hoping it is available to you by default. The risk with trying to read the output of something like ls -l is that group names may contain multiple spaces, but maybe none, so that would cause a mismatch on your field counts.

Looking at my manual page for stat, I would use the -c flag with parameters to get the values like this:-
Code:
$ stat -c '%y' /etc/profile
2017-03-21 21:56:32.000000000 +0000

You could build on this with a loop, e.g.:-
Code:
for filename in *
do
   timestamp=$(stat -c %y $filename)
   ## Trim the timestamp as required or adjust it to your required format
   array_val="${array_val},${timestamp} ${filename}"
done

array_val="${array_val#,}"          # Trim off leading comma
array=("${array_val}")

Does that help? The timestamps from stat would be numeric so depending on your need, you might have to convert them. You might be better using %Y which will give you the value in seconds since the Epoch (1970-01-01 00:00:00) and then convert to the time format you want, perhaps with date if your system supports the -d flag.


Have a try and let us know if that helps or where you get stuck.




Kind regards,
Robin
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What is scp-ed over?

Hi all, i have a directory in server A. the directory path is /home/kevin. I need to scp the directory to another server B. i would like to ask, when i do a scp of the /home/kevin , i can expect all the files from A to go B. However, how about the hidden files? for example the ssh keys in the... (4 Replies)
Discussion started by: new2ss
4 Replies

2. Shell Programming and Scripting

scp

hi can any one pls tell me how to copy a file from a remote host to the same remote host with a timestamp, i need to use only scp. thnks (4 Replies)
Discussion started by: bkan77
4 Replies

3. Shell Programming and Scripting

Query related to scp command

Hi Friends, I need to execute a scp command to transfer some files from source to target server. Unfortunately the ftp is not working in my case. This scp command needs to be executed via Unix script. I need to know the complete scp command which includes the user-id and password of the... (2 Replies)
Discussion started by: sureshg_sampat
2 Replies

4. Shell Programming and Scripting

Is this possible with SCP?

I normally download a directory recursively using: scp -r <name>@host:<path> . This has worked fine. As everyone knows this will download all of the directory named in <path> and all of the sub directories. I would like to know if it is possible to not download a particular file if it... (5 Replies)
Discussion started by: cpabrego
5 Replies

5. Shell Programming and Scripting

add the output of a query to a variable to be used in another query

I would like to use the result of a query in another query. How do I redirect/add the output to another variable? $result = odbc_exec($connect, $query); while ($row = odbc_fetch_array($result)) { echo $row,"\n"; } odbc_close($connect); ?> This will output hostnames: host1... (0 Replies)
Discussion started by: hazno
0 Replies

6. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

7. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

8. UNIX for Dummies Questions & Answers

How to use scp?

How to copy multiple directories using single command on solaris 10 from server A to server B. I tried scp but its working only one directory at atime How to acheive this with simple and short solution????? (6 Replies)
Discussion started by: buzzme
6 Replies
CLEARSTATCACHE(3)							 1							 CLEARSTATCACHE(3)

clearstatcache - Clears file status cache

SYNOPSIS
void clearstatcache ([bool $clear_realpath_cache = false], [string $filename]) DESCRIPTION
When you use stat(3), lstat(3), or any of the other functions listed in the affected functions list (below), PHP caches the information those functions return in order to provide faster performance. However, in certain cases, you may want to clear the cached information. For instance, if the same file is being checked multiple times within a single script, and that file is in danger of being removed or changed during that script's operation, you may elect to clear the status cache. In these cases, you can use the clearstatcache(3) function to clear the information that PHP caches about a file. You should also note that PHP doesn't cache information about non-existent files. So, if you call file_exists(3) on a file that doesn't exist, it will return FALSE until you create the file. If you create the file, it will return TRUE even if you then delete the file. How- ever unlink(3) clears the cache automatically. Note This function caches information about specific filenames, so you only need to call clearstatcache(3) if you are performing multi- ple operations on the same filename and require the information about that particular file to not be cached. Affected functions include stat(3), lstat(3), file_exists(3), is_writable(3), is_readable(3), is_executable(3), is_file(3), is_dir(3), is_link(3), filectime(3), fileatime(3), filemtime(3), fileinode(3), filegroup(3), fileowner(3), filesize(3), filetype(3), and fileperms(3). PARAMETERS
o $clear_realpath_cache - Whether to clear the realpath cache or not. o $filename - Clear the realpath and the stat cache for a specific filename only; only used if $clear_realpath_cache is TRUE. RETURN VALUES
No value is returned. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | Added optional $clear_realpath_cache and $file- | | | name parameters. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 clearstatcache(3) example <?php $file = 'output_log.txt'; function get_owner($file) { $stat = stat($file); $user = posix_getpwuid($stat['uid']); return $user['name']; } $format = "UID @ %s: %s "; printf($format, date('r'), get_owner($file)); chown($file, 'ross'); printf($format, date('r'), get_owner($file)); clearstatcache(); printf($format, date('r'), get_owner($file)); ?> The above example will output something similar to: UID @ Sun, 12 Oct 2008 20:48:28 +0100: root UID @ Sun, 12 Oct 2008 20:48:28 +0100: root UID @ Sun, 12 Oct 2008 20:48:28 +0100: ross PHP Documentation Group CLEARSTATCACHE(3)
All times are GMT -4. The time now is 01:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy