Script Error - JAMF tmp command not found

IamZeus
New Contributor

Hi,

Please I need some assistance, I have had this issue for a while now.

I have 2 policies running a script

the 1st policy modifies a plist via the script and 2nd policy downloads and installs a package using curl and they both have the same issue.

This is the error I'm getting

Error from policy 1

Script result: /Library/Application Support/JAMF/tmp/New Follow Print Plist: line 4: -u: command not found
/Library/Application Support/JAMF/tmp/New Follow Print Plist: line 7: /Users/patsnous/Library/Application\ Support/hcpclient/hcpclient.plist: No such file or directory 2022-03-07 08:37:41.105 defaults[61211:847827] Domain /Users/user/Library/Application\ Support/hcpclient/hcpclient.plist does not exist


Error from policy 2
curl: (23) Failed writing body (0 != 1388) tar: Error opening archive: Failed to open 'elastic-agent-7.16.3-darwin-x86_64.tar.gz' /Library/Application Support/JAMF/tmp/Elastic Agent: line 11: cd: elastic-agent-7.16.3-darwin-x86_64: No such file or directory /Library/Application Support/JAMF/tmp/Elastic Agent: line 13: ./elastic-agent: No such file or directory /Library/Application Support/JAMF/tmp/Elastic Agent: line 15: elastic-agent: command not found

5 REPLIES 5

DBrowning
Valued Contributor II

It would help to see the scripts that are running to better understand the error messages.

IamZeus
New Contributor

The scripts I'm running @DBrowning 

Policy 1

#!/bin/bash
 
logged_in_user=$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ {print $3}')
logged_in_uid=$(id -u "$logged_in_user")
 
result=$(/bin/launchctl asuser "$logged_in_uid" sudo -iu "$logged_in_user")
 
cat << EOF > "/Users/$logged_in_user/Library/Application\ Support/hcpclient/hcpclient.plist"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>account_domain</key>
<string>xxx.xxx.eophcp.com</string>
<key>allow_configuration</key>
<true/>
<key>allow_remember_login</key>
<true/>
<key>auth_type</key>
<integer>0</integer>
<key>delete_printers_on_logout</key>
<false/>
<key>direct_offline_print</key>
<false/>
<key>install_id</key>
<string>xxxxxxxxxxxxxxxxxxx</string>
<key>prompt_type</key>
<integer>0</integer>
<key>ps_to_pdf</key>
<false/>
<key>remember_login</key>
<false/>
<key>server_address</key>
<string>xxx.xxxxx.eophcp.com</string>
<key>storage_type</key>
<integer>1</integer>
<key>sync_interval</key>
<integer>60</integer>
</dict>
</plist>
 
EOF
 
 
defaults read "/Users/$logged_in_user/Library/Application\ Support/hcpclient/hcpclient.plist"

Policy 2

#!/bin/bash

logged_in_user=$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ {print $3}')
logged_in_uid=$(id -u "$logged_in_user")

result=$(/bin/launchctl asuser "$logged_in_uid" sudo -iu "$logged_in_user")

curl -L -O https://xxx.elastic.xxx/downloads/xxx/elastic-agent/elastic-agent-7.16.3-darwin-x86_64.tar.gz
tar -xzvf elastic-agent-7.16.3-darwin-x86_64.tar.gz

cd elastic-agent-7.16.3-darwin-x86_64

./elastic-agent install --force --url=https://xxxxxxxxxxxx.fleet.eu-west-2.aws.cloud.es.io:443 --enrollment-token=XXXXXXXXXX==

elastic-agent status

DBrowning
Valued Contributor II

@IamZeus For the first one, it doesn't look like you call $result anywhere so I would just delete the line defining result (line 4) and I would remove the double quotes around the file path on line 7.  If you are going to keep the quotes, then you will have to remove the \ after Application. Same thing with the last line defaults read.....

#!/bin/bash
 
logged_in_user=$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ {print $3}')

cat << EOF > /Users/$logged_in_user/Library/Application\ Support/hcpclient/hcpclient.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>account_domain</key>
<string>xxx.xxx.eophcp.com</string>
<key>allow_configuration</key>
<true/>
<key>allow_remember_login</key>
<true/>
<key>auth_type</key>
<integer>0</integer>
<key>delete_printers_on_logout</key>
<false/>
<key>direct_offline_print</key>
<false/>
<key>install_id</key>
<string>xxxxxxxxxxxxxxxxxxx</string>
<key>prompt_type</key>
<integer>0</integer>
<key>ps_to_pdf</key>
<false/>
<key>remember_login</key>
<false/>
<key>server_address</key>
<string>xxx.xxxxx.eophcp.com</string>
<key>storage_type</key>
<integer>1</integer>
<key>sync_interval</key>
<integer>60</integer>
</dict>
</plist>
 
EOF

defaults read /Users/$logged_in_user/Library/Application\ Support/hcpclient/hcpclient.plist



For the second one, I would write the file to the /tmp directory using -o and when using the cd command use the full path to the directory.  Also with calling the ./elastic command, use the full path as well.

#!/bin/bash
curl -L https://xxx.elastic.xxx/downloads/xxx/elastic-agent/elastic-agent-7.16.3-darwin-x86_64.tar.gz -o /private/tmp/elastic-agent-7.16.3-darwin-x86_64.tar.gz
tar -xzvf /private/tmp/elastic-agent-7.16.3-darwin-x86_64.tar.gz

cd /private/tmp/elastic-agent-7.16.3-darwin-x86_64

/private/tmp/elastic-agent-7.16.3-darwin-x86_64/elastic-agent install --force --url=https://xxxxxxxxxxxx.fleet.eu-west-2.aws.cloud.es.io:443 --enrollment-token=XXXXXXXXXX==

elastic-agent status


Give those a shot.

IamZeus
New Contributor

Hi @DBrowning , thank you for your help, plist script appears to work now.

Im getting this new error for the elastic agent script, unable to create directory, could it be a permission issue?

x elastic-agent-7.16.3-darwin-x86_64/: Can't create 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/elastic-agent: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/elastic-agent.reference.yml: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/elastic-agent.yml: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/README.md: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/NOTICE.txt: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/.build_hash.txt: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/LICENSE.txt: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/.elastic-agent.active.commit: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/elastic-agent: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/filebeat-7.16.3-darwin-x86_64.tar.gz.sha512: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/fleet-server-7.16.3-darwin-x86_64.tar.gz: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/filebeat-7.16.3-darwin-x86_64.tar.gz: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/apm-server-7.16.3-darwin-x86_64.tar.gz: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/fleet-server-7.16.3-darwin-x86_64.tar.gz.asc: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/osquerybeat-7.16.3-darwin-x86_64.tar.gz.asc: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/endpoint-security-7.16.3-darwin-x86_64.tar.gz.asc: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/osquerybeat-7.16.3-darwin-x86_64.tar.gz.sha512: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/metricbeat-7.16.3-darwin-x86_64.tar.gz.sha512: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/apm-server-7.16.3-darwin-x86_64.tar.gz.sha512: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/heartbeat-7.16.3-darwin-x86_64.tar.gz.sha512: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/fleet-server-7.16.3-darwin-x86_64.tar.gz.sha512: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/heartbeat-7.16.3-darwin-x86_64.tar.gz: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/metricbeat-7.16.3-darwin-x86_64.tar.gz.asc: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/apm-server-7.16.3-darwin-x86_64.tar.gz.asc: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/filebeat-7.16.3-darwin-x86_64.tar.gz.asc: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/osquerybeat-7.16.3-darwin-x86_64.tar.gz: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/endpoint-security-7.16.3-darwin-x86_64.tar.gz: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/heartbeat-7.16.3-darwin-x86_64.tar.gz.asc: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/endpoint-security-7.16.3-darwin-x86_64.tar.gz.sha512: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' x elastic-agent-7.16.3-darwin-x86_64/data/elastic-agent-d420cc/downloads/metricbeat-7.16.3-darwin-x86_64.tar.gz: Failed to create dir 'elastic-agent-7.16.3-darwin-x86_64' tar: Error exit delayed from previous errors. /Library/Application Support/JAMF/tmp/Elastic Agent: line 7: cd: /private/tmp/elastic-agent-7.16.3-darwin-x86_64: No such file or directory /Library/Application Support/JAMF/tmp/Elastic Agent: line 9: /private/tmp/elastic-agent: No such file or directory /Library/Application Support/JAMF/tmp/Elastic Agent: line 11: elastic-agent: command not found

MacJunior
Contributor III

@IamZeus did it work for you? i'm having the same issue !