Results 1 to 9 of 9

Thread: Postfix delivers message but script not run

  1. #1
    Join Date
    May 2009
    Location
    #bcstx
    Beans
    17

    Unhappy Postfix delivers message but script not run

    Hi, I'm trying to get messages sent to an alias to invoke a ruby script.

    Looking at the postfix log the message is being delivered, but I believe the script isn't being run with sufficient permissions.

    Jun 3 18:31:21 hostname postfix/local[12968]: 340B911A3B4: to=<email@domain.com>, relay=local, delay=0.24, delays=0.2/0.01/0/0.03, dsn=2.0.0, status=sent (delivered to command: /var/mailscripts/script)
    The script is really simple:

    Code:
    #!/usr/bin/env ruby1.9
    
    text = ARGV[0]
    
    puts `echo "#{text}" >> /var/mailscripts/myfile`
    It should just write the message to myfile. I'm not exactly sure what user/group postfix runs under, and I believe this is the heart of my problem.

  2. #2
    Join Date
    May 2006
    Location
    Switzerland
    Beans
    2,907
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Postfix delivers message but script not run

    So ... we're basically talking about a mail-bot, right? I wrote one too ... it's a relatively simple and stupid shell script that gets auto-executed every 15 minutes, connects to a Google account and then downloads and executes the commands I sent to it.

    If you want I'll post it here ... ?

  3. #3
    Join Date
    May 2009
    Location
    #bcstx
    Beans
    17

    Re: Postfix delivers message but script not run

    No, I'm using the alias file to invoke a script. Like this:

    alias: |/var/mailscripts/script
    Thanks for responding though.

  4. #4
    Join Date
    May 2006
    Location
    Switzerland
    Beans
    2,907
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Postfix delivers message but script not run

    Quote Originally Posted by rstackhouse View Post
    No, I'm using the alias file to invoke a script.
    Hmmm ... I don't get it. What's the purpose of this?

    My mail-bot will download a mail from a specific account (can be configured), do some basic checks and then execute whatever command it was sent, and then send the results back to a specific recipient account (can be configured too). Basically everything that doesn't require keyboard input will work tip top. I can trigger downloads via wget and gcc compile jobs just by writing an e-mail. So yes, it's kind of a backdoor back into the system. I needed that because that particular place where it's installed is behind a super-flaky and unstable router, and sometimes all OpenVPN processes are hanging. Very often this "backdoor" is the only way back in ... the only other alternative would be to get into a car and drive 100 km to the server room.

    Are you trying to implement something like this (I suppose my flaky router isn't the only one on this planet ... ?) or am I totally misunderstanding your intentions and goals?

  5. #5
    Join Date
    Jul 2008
    Beans
    7

    Re: Postfix delivers message but script not run

    Quote Originally Posted by scorp123 View Post
    Hmmm ... I don't get it. What's the purpose of this?
    Probably to have it real time as opposed of having to spool a mailbox from time to time. That's how the mailing list managers handles the msg for instance.

    What are the permission of ?

    /var/mailscripts/myfile

    (or /var/mailscripts)

    If you want to write some bot or something, have a look at lamsonproject.org might provide you a good framework and take care of quite a few tedious stuff.

  6. #6
    Join Date
    May 2009
    Location
    #bcstx
    Beans
    17

    Re: Postfix delivers message but script not run

    Quote Originally Posted by scorp123 View Post
    Hmmm ... I don't get it. What's the purpose of this?
    sydesy hit it right on the nose. I want to take messages delivered to a particular email alias and relay them to an HTTP based messaging service in near real time.

    A fellow seemed to have similar woes over here.

    From what he's saying, it looks like you have to have a user in Ubuntu that matches the name of the email alias that is sending the mail message to a script.

    I had just assumed that the script would be invoked under either root or the account running postfix.

    I am still a bit of a newb, especially when it comes to permissions.
    Last edited by rstackhouse; June 6th, 2010 at 03:21 PM.

  7. #7
    Join Date
    May 2006
    Location
    Switzerland
    Beans
    2,907
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Postfix delivers message but script not run

    Quote Originally Posted by rstackhouse View Post
    sydesy hit it right on the nose. I want to take messages delivered to a particular email alias and relay them to an HTTP based messaging service in near real time.

    A fellow seemed to have similar woes over here.
    Ah OK ... I get it now

  8. #8
    Join Date
    May 2009
    Location
    #bcstx
    Beans
    17

    Re: Postfix delivers message but script not run

    I changed the script to
    Code:
    #!/usr/bin/env ruby1.9
    require 'etc'
    
    text = "ARGV.length #{ARGV.length} login #{Etc.getlogin}"
    
    puts `echo "#{text}" >> /var/mailscripts/myfile`
    and chmoded /var/mailscripts to 777. When I do this, it shows me the script is being invoked by my user with the same name as my alias, but ARGV.length is 0. IOW, it looks like the message contents aren't being passed to the script.

    the user owns the script directory and the script itself, but if I chmod both back to 755, the file won't get created, but it will get appended to if it is already there.

  9. #9
    Join Date
    May 2009
    Location
    #bcstx
    Beans
    17

    Re: Postfix delivers message but script not run

    I changed the script and now the message gets written to file, but there is still the permissions issue

    Code:
    #!/usr/bin/env ruby1.9
    require 'fcntl'
    
    #http://blog.footle.org/2008/08/21/checking-for-stdin-inruby/
    
    text = ""
    
    if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0 #check stdin for message
            text = "got something: #{STDIN.read}"
    elsif ARGV.length > 0 #check command line arguments
            text = "got something:  #{ARGV[0]}"
    else
            text = "no message found"
    end
    
    File.open('/path/to/myfile', 'w') {|f| f.write(text) }

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •