You are not logged in.

#1 2009-03-15 17:20:04

Dethredic
Member
Registered: 2009-01-24
Posts: 361
Website

Noob: Need Help With Some Scripts (python / bash)

Ok, I have been using Arch for the last month and Linux for the last 3 months. I have really come to enjoy it, and the switch to Arch taught my a lot but I still feel like I know nothing in the grand scheme of things.

I know 0 python and very very little bash but I am open to learning.

I have a few script ideas which I would like to implement, but I will need help doing so.

1) Make an "Upload File" custom action in Thunar.

I found this python script in the massive scripts thread:

#!/usr/bin/env python

import ftplib
import os
import sys

if len(sys.argv) < 2:
    print "Usage: %s file [file2] [file3] ..." % os.path.split(sys.argv[0])[1]
    sys.exit()

# Clear the screen?
#os.system('clear')
print "Files to upload:"
print sys.argv[1:], "\n"
ftp = ftplib.FTP('www.xxx.com')
login  = "xxx"
passwd = "xxx"

ftp.login(login, passwd)
ftp.dir()
dir = "/public_html/up/"
ftp.cwd(dir)
# Move to the desired upload directory.
#dir = raw_input("\nType the directory name (leave empty to use the current dir): ")
#if dir:
#    ftp.cwd(dir)
#
print "\nCurrently in:", ftp.pwd()

for file in sys.argv[1:]:
    name = os.path.split(file)[1]
    print "Uploading \"%s\" ..." % name,
    f = open(file, "rb")
    ftp.storbinary('STOR ' + name, f)
    f.close()
    print "OK"

print "Quitting..."
ftp.quit()

Now that script works great, but it would be nice to be able to right click a file/folder and use a custom action to run the script and upload what I right clicked on. I have the custom action running the script, but that wouldn't make the selected file appear in the command.

2)
My second script idea is one that updates my MP3 player. It would delete any files that are on it that are not found in my ~/music dir, and copy over any files that are found in ~/music but not in my MP3 player's dir.
Not sure how I would go about doing that.
EDIT: rsync -a -r --delete /dir /dir worked great!

Last edited by Dethredic (2009-03-15 17:37:24)

Offline

#2 2009-03-15 17:34:03

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Noob: Need Help With Some Scripts (python / bash)

1. So a file manager problem? What file manager?

2. rsync -a --delete ~/music /mnt/mp3player

Offline

#3 2009-03-15 17:36:44

Dethredic
Member
Registered: 2009-01-24
Posts: 361
Website

Re: Noob: Need Help With Some Scripts (python / bash)

Procyon wrote:

1. So a file manager problem? What file manager?

2. rsync -a --delete ~/music /mnt/mp3player

the rsync command worked great!

My file manager is Thunar

Offline

#4 2009-03-15 17:48:51

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Noob: Need Help With Some Scripts (python / bash)

-a implies -r, by the way.

No idea about Thunar.

Offline

#5 2009-03-15 18:48:19

Dethredic
Member
Registered: 2009-01-24
Posts: 361
Website

Re: Noob: Need Help With Some Scripts (python / bash)

blah, ok I got the thunar one. I was just dumb and forgot to put the %N at the end.

Offline

Board footer

Powered by FluxBB