Created 12-27-2016 07:22 AM
Hi Team,
I have used ambari-ldap sync script but I get the following error when I ran the below command. One thing I noticed is that if the run the script manually as ./ambari_ldap_sync_all.sh then its getting executed.
Also I have shown my ambari-ldap sync script below. So the script is not getting executed from crontab with 'sh' command .
[root@host1(172.23.34.4)] # sh ambari_ldap_sync_all.sh ambari_ldap_sync_all.sh: line 3: spawn: command not found couldn't read file "Enter Ambari Admin login:": no such file or directory ambari_ldap_sync_all.sh: line 7: send: command not found couldn't read file "Enter Ambari Admin password:": no such file or directory ambari_ldap_sync_all.sh: line 11: send: command not found couldn't read file "eof": no such file or directory [root@host1(172.23.34.4)] # cat ambari_ldap_sync_all.sh #!/usr/bin/expect spawn ambari-server sync-ldap --existing expect "Enter Ambari Admin login:" send "admin\r" expect "Enter Ambari Admin password:" send "admin\r" expect eof [root@host1(172.23.34.4)] # crontab -e 00 15 * * * /ambari_ldap_sync_all.sh
Can someone help me how to write expect script if it is required??
Created 01-04-2017 08:19 AM
Finally I am able to resolve the issue.
1. I changed the script extension from ambari_ldap_sync_all.sh to ambari_ldap_sync_all.exp
2. I also changed the absolute path of ambari-server as /usr/sbin/ambari-server and added exit statement at the end of script.
#!/usr/bin/expect spawn /usr/sbin/ambari-server sync-ldap --existing expect "Enter Ambari Admin login:" send "admin\r" expect "Enter Ambari Admin password:" send "admin\r" expect eof exit
3. Finally inside the crontab, I made the entry as
0 23 * * * /usr/bin/expect /opt/ambari_ldap_sync_all.exp
Created 12-27-2016 07:30 AM
Created 12-27-2016 07:41 AM
Yes expect package is already installed. Actually my issue is the script is not getting executed at 3pm even though it is configured in crontab. As I said, when I ran the command manually as ./ambari_ldap_sync_all.sh then it works. So is there any alternative how the script can get executed automatically from crontab?
Created 12-27-2016 07:46 AM
The error that you posted clearly indicates that the packages are not properly installed (OR) the current users PATH does is not correct. (OR) after installing the "expect" package you have not included the "#!/usr/bin/expect" at the beginning of your script.
ambari_ldap_sync_all.sh: line 3: spawn: command not found ambari_ldap_sync_all.sh: line 7: send: command not found
- Please double check those packages. Command like "spawn" comes from expect package.
- As you are able to run the command manually, which means these commands might now be available in your PATH variable when you are running them using cron.
So please fix the PATH to include the PATH to point to the location of these commands
.
Created 12-27-2016 07:56 AM
Regarding your query: "is there any alternative how the script can get executed automatically from crontab?"\
crontab -e
Then add the following entry in the crontab:
0 15 * * * /PATH/TO/ambari_ldap_sync_all.sh
However above approach has nothing to do with HDP or Ambari. It's simple Linux.
Created 01-04-2017 08:19 AM
Finally I am able to resolve the issue.
1. I changed the script extension from ambari_ldap_sync_all.sh to ambari_ldap_sync_all.exp
2. I also changed the absolute path of ambari-server as /usr/sbin/ambari-server and added exit statement at the end of script.
#!/usr/bin/expect spawn /usr/sbin/ambari-server sync-ldap --existing expect "Enter Ambari Admin login:" send "admin\r" expect "Enter Ambari Admin password:" send "admin\r" expect eof exit
3. Finally inside the crontab, I made the entry as
0 23 * * * /usr/bin/expect /opt/ambari_ldap_sync_all.exp