-2

At work on a Linux server, I try to find a way to execute a script by crontab(in root) for:

  • Log into a local user by ssh with the command ssh -X user@localhost
  • answer at the password question for the user
  • execute a command
  • wait the end
  • exit ssh session

I make the process because it works when I do this manually.

I can't use crontab Otherwise than in root. I try to add a public key for avoid the password step but I don't succeed into. I must execute my command log into a specific user. And finally I find a way to get environnement variables with the options -X ... if I log into the specific user with the command su -l user ... my command won't works.

I don't know if I am clear, I am sorry because my knowledge in Linux environments are limited and I try my best to explain to you in an approximate English (I'm French)

Best regards

Squashman
  • 13,649
  • 5
  • 27
  • 36
shinji7800
  • 53
  • 6
  • 1
    Use the user's crontab for this: `crontab -e -u ` – Ipor Sircer Nov 02 '17 at 16:35
  • 1
    You haven't included any of your code and you haven't described exactly how your script is failing. What is your actual question here? There are lots of questions on this site about automating ssh. – Kenster Nov 02 '17 at 16:55
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Nov 02 '17 at 19:44
  • @ipor-sircer I will try to edit crontab that specific user from root user with your command (crontab -e -u ) I doesn't know that was possible thanks you for the tip. – shinji7800 Nov 02 '17 at 20:58
  • @jww Thanks I doesn't know this website I will try here sorry to miss that – shinji7800 Nov 02 '17 at 21:00

1 Answers1

0

Sorry I may not enough explicit I will try differently

First of all my first message is not too specific because I don't know if my way to deal with my issue is the best way that why I had explain it in a general way

Like I said I must configure crontab with root user, but the command (specific command of an application installed on my Linux server) that I try to execute automatically must be execute with a specific server user.

With all those constraints I try to develop an except script

[code]

!/usr/bin/expect

spawn ssh -X specific-user@localhost expect "assword :" send "PASSWORD\r" sleep 10 SpecificUtility + some parameters Expect "localhost #" Send "exit\r" interact [/code]

If I execute this script manually it is ok but in crontab the sequence if not respected

I do something wrong but I have no clue

I hope explain it better

Best regards

Community
  • 1
  • 1
shinji7800
  • 53
  • 6