LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-31-2005, 07:23 AM   #1
ReefShark
Member
 
Registered: Oct 2003
Location: the Netherlands
Distribution: Arch Linux, Ubuntu server
Posts: 145

Rep: Reputation: 15
KSH: syncing three files the hard way


I am working on a script (ksh) and I could use a few pointers in the right direction.

The point where am currently stuck is this:
I have 3 copies of the same file on three machines (1 linux, 2 windows) which I can read through samba mounts. I need to check which file has most recently changed since the last run of the script.

I also want to find a way (preferrably as a normal user) if eth2 is up, or another way to see if I am on my home network (I run the script on my office laptop, so I don't want the script to run from crontab if I am at work).

There are a few bumps further down the road, but hopefully I can find a solution myself for those. Hope someone can give me a pointer in the right direction.

Thanks in advance.
 
Old 07-31-2005, 10:56 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Problem one:

Code:
#!/bin/ksh

# change these to your liking
FILE01="/path/to/file"
FILE02="/other/path/to/file"
FILE03="/another/path/to/file"

FILE01_TS="`ls -l --time-style=+%Y%m%d%H%M ${FILE01} | cut -d" " -f7`"
FILE02_TS="`ls -l --time-style=+%Y%m%d%H%M ${FILE02} | cut -d" " -f7`"
FILE03_TS="`ls -l --time-style=+%Y%m%d%H%M ${FILE03} | cut -d" " -f7`"

NEWEST_FILE="${FILE01}"
NEWEST_TS="${FILE01_TS}"

if (( FILE01_TS < FILE02_TS ))
then
  NEWEST_TS="${FILE02_TS}"
  NEWEST_FILE="${FILE02}"
fi

if (( NEWEST_TS < FILE03_TS ))
then
  NEWEST_TS="${FILE03_TS}"
  NEWEST_FILE="${FILE03}"
fi

echo ${NEWEST_FILE}
Maybe not to elegant, but it works.

Problem 2:

Can't you use ping (ping -c 1 <machine>) to check this?

Hope this gets you going again.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving Hard Drive Files Zawi Linux - General 10 08-17-2005 11:08 AM
three hard drives (for backing up files) cadkins Linux - Hardware 3 12-16-2004 05:10 PM
How I got a hard drive to accept files again jonr LinuxQuestions.org Member Success Stories 2 11-13-2004 06:04 PM
Recovering Hard Drive files CycloLink Linux - Hardware 6 01-29-2004 07:59 PM
How do i read files from another hard disk? timberwolf Linux - Networking 10 12-03-2003 09:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration