I want to execute the script without using execute resource or script resource

Hi
I am trying to run the script but do not want to use the execute or script resource as it will execute every 30 mins also guards are blocked for my env .Hence need a help if we can re write the below code some other way without these resources.

Thanks in advance.

script 'user' do
interpreter 'bash'
user 'root'
code <<-EOH
adduser -g test1 test2
EOH
end

this has to be written without execute or script resource.

and also second code being:

script 'executing_installation' do
interpreter 'bash'
user 'root'
code <<-EOH
sh /test/some/script/recipe.sh >> /tmp/test.txt
EOH
cwd /tmp/tmp2
end

script 'port_redirection' do
interpreter 'bash'
user 'root'
code <<-EOH
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
chmod +x /etc/test/test1
EOH
end

These has to be written without execute or script resource .

kindly help me on this with relevant example will be much help.

Thanks in advance

Have a look at Mixlib::ShellOut

If you're using chef then you definitely want to be using Resources - what it sounds like you want is to only execute these resources once and you can use guards like only_if or not_if. Even if using the Mixlib:ShellOut it would run everytime if part of a recipe.

script 'user' do
interpreter 'bash'
user 'root'
code <<-EOH
adduser -g test1 test2
EOH
end

replace this with

group  'test1' do
  action :create
end

user 'test2' do
  manage_home true
  password encrypted_password_string
  group 'test1'
  shell '/bin/bash'
  comment 'test user 2'
  action :create
end

script 'executing_installation' do
interpreter 'bash'
user 'root'
code <<-EOH
sh /test/some/script/recipe.sh >> /tmp/test.txt
EOH
cwd /tmp/tmp2
end

You can use a bash block here but its effectively the same you would still need a guard

bash 'executing_installation' do
  cwd /tmp/tmp2
  code <<-EOH
  sh /test/some/script/recipe.sh >> /tmp/test.txt
  EOH
end

script 'port_redirection' do
interpreter 'bash'
user 'root'
code <<-EOH
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
chmod +x /etc/test/test1
EOH
end

Same for this block of code

bash 'executing_installation' do
  code <<-EOH
  iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
  EOH
end

This you would need to just specify the node and it will change the file permissions

file '/etc/test/test1' do
mode '0755'
end

Why are you not allowed to use guards?