Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, for a daily server audit script, I'm sending the log file to a central offsite server. To do this, I'm using su user1 -c 'scp myfile.log remoteuser1@remoteserver:/home/remoteuser1/Documents/logs' This works ...
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99

    Include variable in quoted command set

    Hi,

    for a daily server audit script, I'm sending the log file to a central offsite server.
    To do this, I'm using

    su user1 -c 'scp myfile.log remoteuser1@remoteserver:/home/remoteuser1/Documents/logs'

    This works fine.
    However, I would like to include a variable between the quotes. That's where it fails.

    For example

    su user1 -c 'scp $MYFILE remoteuser1@remoteserver:/home/remoteuser1/Documents/logs'

    gives a usage echo for scp

    Is there a workaround for this?
    I have to su as a different user for authentication purposes.

    Marinus.

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Hi,

    Single quotes prevent the shell to expand the variable, try double quotes:

    Code:
    su user1 -c "scp $MYFILE remoteuser1@remoteserver:/home/remoteuser1/Documents/logs"
    Regards

  3. #3
    Just Joined!
    Join Date
    Aug 2005
    Posts
    99
    Hello Franklin,

    that you very much. That was it.

    Marinus.

Posting Permissions

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