LinuxQuestions.org
Visit Jeremy's Blog.
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 04-19-2005, 05:19 AM   #1
Baran
Member
 
Registered: Aug 2003
Location: Tampere-FINLAND
Distribution: Mandrake 10.1
Posts: 105

Rep: Reputation: 15
I need to write a short script


Hello,

I need to write a short script, I didn't do such a thing before so I actually don't have any idea.

The script is supposed to do these:

- Every morning at 10:00 o'clock it will lauch korganiser
- Take a screenshot of the window by using ksnapshot
- Save the file to desktop with the name TodaysPlans.jpg
- Login to a remote server using ssh (I can already do that manually, but dont know how to login using one line only)
- Rename the TodaysPlans.jpg in the server with the new name <YesterdaysDate>.jpg
- Upload the TodaysPlans.jpg to the server
- Logout


This is all I want

It shouldn't be that difficult. But I really need your help.

Thanks in advance

-Baran
 
Old 04-19-2005, 05:44 AM   #2
pycoucou
Member
 
Registered: Apr 2004
Location: Edinburgh
Posts: 78

Rep: Reputation: 15
Hi Baran,

some tips to do so:

For the scheduler: use cron/at to lauch your script at 10AM. Cron is quite simple, check the help.
For the screenshot, I don't know ksnapshot but you probably know it, to perform the shot with a command line.

To change the name on the server, do ssh login@server command (you cannot work interactively).
To have access, use RSA key (man ssh-keygen). You would be identified without giving a password.

And then use scp to remotely copy your snashot to the server.

This algorithm should work. I let you with the manpages/help/howtos that blossomed on internet.

Cheers,
PY
 
Old 04-19-2005, 05:45 AM   #3
pycoucou
Member
 
Registered: Apr 2004
Location: Edinburgh
Posts: 78

Rep: Reputation: 15
Oops.. I forgot to laucnh korganiser... Hmm, the dirty way I see is to do so by lauching it as a background task and then kill it.... I'm not happy with this solution but it should work.
 
Old 04-19-2005, 06:16 AM   #4
Baran
Member
 
Registered: Aug 2003
Location: Tampere-FINLAND
Distribution: Mandrake 10.1
Posts: 105

Original Poster
Rep: Reputation: 15
Hi,

Thanks for the reply, it seems a little easier now, still I cannot do that completely. However:

- After running korganiser in the background, how can I kill it without knowing its PID? Is there way to kill in other ways?
 
Old 04-19-2005, 06:19 AM   #5
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
Code:
killall korganiser
will kill it for you.
 
Old 04-19-2005, 06:33 AM   #6
ahwkong
Member
 
Registered: Aug 2004
Location: Australia
Distribution: Fedora
Posts: 282

Rep: Reputation: 30
$! in bash will also give you the PID of last executed process

Check it out:

section 3.2.5. Special parameters

in

http://www.tldp.org/LDP/Bash-Beginne...ect_03_02.html
 
Old 04-19-2005, 09:30 AM   #7
Baran
Member
 
Registered: Aug 2003
Location: Tampere-FINLAND
Distribution: Mandrake 10.1
Posts: 105

Original Poster
Rep: Reputation: 15
Ok !

I read help documents about ksnapshot but I couldn't figure out a way to take a snapshot of a window in KDE.

Is there way that you can suggest to take a snapshot and save it using the command line?
 
Old 04-19-2005, 09:42 AM   #8
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
X Window Capturing a screen shot: Five methods
Code:
1. XAUTHORITY=/var/gdm/:0.Xauth DISPLAY=:0.0 import -window root image.png
2. import -window root image.jpg		4. Alt + Print Screen
3. xwd -display :0 -root >image.xwd	5. Ksnapshot
    convert image.xwd image.jpg
Try using import ( #2 ) as it may be easiest for you.

You can also use script or setterm but they are for capturing text in the console, not windows.
 
Old 04-19-2005, 03:29 PM   #9
Baran
Member
 
Registered: Aug 2003
Location: Tampere-FINLAND
Distribution: Mandrake 10.1
Posts: 105

Original Poster
Rep: Reputation: 15
Thanks everyone for the support

Now I started to write it.

I guess

import -window root image.jpg

works perfectly. So I will use that one.

I guess I have only one problem left

Which is to login to the remote server with the command line without any password prompt.

I read the documents about ssh and ssh-keygen but they are not clear. I didn't understand where to create the keys, in the local machine or the remote and what should I do with the key?
 
Old 04-22-2005, 09:55 AM   #10
pycoucou
Member
 
Registered: Apr 2004
Location: Edinburgh
Posts: 78

Rep: Reputation: 15
A couple of days later...

ssh-keygen generates two files
- private id
- public id

if you want to go from login1@computer1 to login2@computer2 using these keys you need to save the private id as ~login1/.ssh/identity on computer1 and the public id on ~login2/.ssh/authorized_keys.

Now if as login1 on computer1, you type ssh computer2 -l login2, the authentification happens through the exchange of key and you don't need any password.
 
  


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
wanna write a script djflix Linux - Newbie 4 09-07-2005 11:54 AM
How to write a Script Blake Linux - Software 6 07-18-2004 11:41 AM
how to write this script? MeganageM Linux - Newbie 1 03-10-2004 05:01 PM
Help with a script I need to write... cmfarley19 Programming 9 12-06-2003 12:10 PM
Short write eric.houben Linux - General 2 07-13-2001 09:12 AM

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

All times are GMT -5. The time now is 10:18 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