Getting remove_entry_secure error while using ruby application - ruby

I am trying to split PDF files into images using docsplit. But it appears I have issues with my ruby installation. I keep getting the following error every time:
/usr/lib/ruby/1.8/fileutils.rb:694:in `remove_entry_secure': parent directory is world writable
Here is the full command line output:
$ docsplit images pdf-test.pdf
/usr/lib/ruby/1.8/fileutils.rb:694:in `remove_entry_secure': parent directory is world writable, FileUtils#remove_entry_secure does not work; abort: "/tmp/d20130207-6739-1f9i6b" (parent directory mode 42777) (ArgumentError)
from /var/lib/gems/1.8/gems/docsplit-0.6.4/lib/docsplit/image_extractor.rb:51:in `convert'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/lib/docsplit/image_extractor.rb:19:in `extract'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/lib/docsplit/image_extractor.rb:19:in `each'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/lib/docsplit/image_extractor.rb:19:in `extract'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `each_with_index'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/lib/docsplit/image_extractor.rb:18:in `each'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/lib/docsplit/image_extractor.rb:18:in `each_with_index'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/lib/docsplit/image_extractor.rb:18:in `extract'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/lib/docsplit/image_extractor.rb:16:in `each'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/lib/docsplit/image_extractor.rb:16:in `extract'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/lib/docsplit.rb:63:in `extract_images'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/bin/../lib/docsplit/command_line.rb:44:in `run'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/bin/../lib/docsplit/command_line.rb:37:in `initialize'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/bin/docsplit:5:in `new'
from /var/lib/gems/1.8/gems/docsplit-0.6.4/bin/docsplit:5
from /usr/bin/docsplit:19:in `load'
from /usr/bin/docsplit:19
Any ideas on how to fix this?

It turns out there was a problem with my /tmp folder permissions. The following fixed the problem:
Steps that I followed are:
user#host-$: chmod 777 -R /tmp
user#host-$: chmod o+t -R /tmp
user#host-$: ls -l tmp
drwxrwxrwt 2 user group 4096 2009-11-21 17:01 tmp

Related

How to pass -m argument to sambal gem?

I have downloaded the sambal gem. Here is my smbclient command which I know works:
smbclient \\10.9.167.71\Dept -U CORP\thinger -m SMB2
I want to instantiate a sambal client object using those exact same parameters. Here is what I tried:
client = Sambal::Client.new(domain: 'CORP', host: '10.9.167.71', share: 'Dept', user: 'thinger', password: '--no-pass')
-m SMB2 gets left out of the equation, but I know it has to exist in order for this to work. Reviewing the documentation I see no way to pass this argument. So then it's not surprising I get this:
Traceback (most recent call last):
3: from test.rb:6:in `<main>'
2: from test.rb:6:in `new'
1: from /usr/local/bundle/gems/sambal-0.2.2/lib/sambal/client.rb:29:in `initialize'
/usr/local/bundle/gems/sambal-0.2.2/lib/sambal/client.rb:67:in `rescue in initialize': Unknown Process Failed!! (Failed to connect): "Failed to connect" (RuntimeError)
/usr/local/bundle/gems/sambal-0.2.2/lib/sambal/client.rb:64:in `initialize'
test.rb:6:in `new'
test.rb:6:in `<main>'
Is there a way? Reviewing this turns up nothing I can see, but it is plausible I am just not experienced enough to understand:
https://github.com/johnae/sambal/blob/master/lib/sambal/client.rb
I want to try to avoid using the smbclient commands directly in my ruby script - it seems, simply, a painful way to do things. I will do it if I have to, though.
The -m flag to smbclient is an alias to --max-protocol.
This flag can be set in sambal by passing the the max_protocol option to the initializer. With your other options, this will look like:
client = Sambal::Client.new(domain: 'CORP', host: '10.9.167.71', share: 'Dept', user: 'thinger', password: '--no-pass', max_protocol: 'SMB2')

How to fix Parser Error in gherkin when I write the code with ruby for automate test

I created search.feature and search.rb files to build automatic testing. After that, I run with the command on the terminal and get an error. How to fix it?
I've tried on Linux subsystem on windows with Ruby 2.6.1 and Cucumber 3.1.2
This is the code of search.feature file :
The google homepage allows user to perform a search.
Scenario Outline: Users can perform a search on Google
Given I open the Google search page
When I search for "<search>"
Then I should see the results page
Examples :
| search |
| baju |
| bola |
| indonesia |
And this is the code of search.rb file :
Given /^I open the Google search page$/ do
visit "/"
end
Given /^I search for "(.*?)"$/ do |search_term|
#page_search = SearchPage.new
#page_search.search(search_term)
end
Then /^I should see the results page$/ do
expect(#page_search).to have_search_field
end
After that, when I run the command on the terminal I get an error like this :
➜ cucumber-native cucumber
features/scenario/search/search.feature: Parser errors:
(9:2): expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ExamplesLine, #ScenarioLine, #ScenarioOutlineLine, #Comment, #Empty, got 'Examples :' (Cucumber::Core::Gherkin::ParseError)
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core/gherkin/parser.rb:34:in `rescue in document'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core/gherkin/parser.rb:28:in `document'/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:30:in `block in parse'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:29:in `each'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:29:in `parse'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:21:in `compile'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-3.1.2/lib/cucumber/runtime.rb:75:in `run!'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-3.1.2/lib/cucumber/cli/main.rb:34:in `execute!'
/home/oimtrust/.rvm/gems/ruby-2.6.1/gems/cucumber-3.1.2/bin/cucumber:9:in `<top (required)>'
/home/oimtrust/.rvm/gems/ruby-2.6.1/bin/cucumber:23:in `load'
/home/oimtrust/.rvm/gems/ruby-2.6.1/bin/cucumber:23:in `<main>'
/home/oimtrust/.rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `eval'
/home/oimtrust/.rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `<main>'
Examples section must be nested within Scenario
Scenario Outline: Users can perform a search on Google
Given I open the Google search page
When I search for "<search>"
Then I should see the results page
Examples:
| search |
| baju |
| bola |
| indonesia |

Vagrant: missing file id_rsa

I'm using windows with homestead and I'm trying to enter vagrant up on the command line but I'm getting this error:
C:/www/Homestead/scripts/homestead.rb:106:in read': No such file or directory # rb_sysopen - C:/Users/Niall/.ssh/id_rsa (Errno::ENOENT)
from C:/www/Homestead/scripts/homestead.rb:106:inblock (2 levels) in configure'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/kernel_v2/config/vm_provisioner.rb:72:in call'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/kernel_v2/config/vm_provisioner.rb:72:inadd_config'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/plugins/kernel_v2/config/vm.rb:321:in provision'
from C:/www/Homestead/scripts/homestead.rb:103:inblock in configure'
from C:/www/Homestead/scripts/homestead.rb:102:in each'
from C:/www/Homestead/scripts/homestead.rb:102:inconfigure'
from C:/www/Homestead/Vagrantfile:20:in block in <top (required)>'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/config/v2/loader.rb:37:incall'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/config/v2/loader.rb:37:in load'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/config/loader.rb:113:inblock (2 levels) in load'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/config/loader.rb:107:in each'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/config/loader.rb:107:inblock in load'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/config/loader.rb:104:in each'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/config/loader.rb:104:inload'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/vagrantfile.rb:28:in initialize'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/environment.rb:740:innew'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/environment.rb:740:in vagrantfile'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/environment.rb:486:inhost'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/environment.rb:208:in block in action_runner'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/action/runner.rb:33:incall'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/action/runner.rb:33:in run'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/environment.rb:473:inhook'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/lib/vagrant/environment.rb:722:in unload'
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/bin/vagrant:177:inensure in '
from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.8.1/bin/vagrant:177:in `'
I searched online but all I could find was someone else asking the same question but no answer. What does this error mean? I went to the folder in particular and indeed there is no file called id_rsa. Can anyone shine some light on how to rectify this?
It looks like you need to generate an SSH key? You can do that by entering the command ssh-keygen -t rsa -C "your_email#example.com" (with your own email obviously) if you're using Git Bash.
When it prompts you for where to save the key just hit enter. Passphrase is also optional, just hit enter twice for a blank passphrase.

Net::SFTP::Session can't run stat, apparently has a Nil channel

So I have some code that checks if there's a certain file on remote SFTP server:
def size
adapter.sftp.stat(path).size
end
where sftp is a Net::SFTP::Session object defined in this case as
#sftp = Net::SFTP.start(host, username, password: password)
and path is the file path to the object that I want to call stat() on.
Unfortunately, when I try to excecute this code, I get this error:
NoMethodError:
undefined method `send_data' for nil:NilClass
# /usr/local/lib/ruby/gems/2.2.0/gems/net-sftp-2.1.2/lib/net/sftp/session.rb:814:in `send_packet'
# /usr/local/lib/ruby/gems/2.2.0/gems/net-sftp-2.1.2/lib/net/sftp/protocol/base.rb:45:in `send_request'
# /usr/local/lib/ruby/gems/2.2.0/gems/net-sftp-2.1.2/lib/net/sftp/protocol/01/base.rb:90:in `open'
# /usr/local/lib/ruby/gems/2.2.0/gems/net-sftp-2.1.2/lib/net/sftp/session.rb:830:in `request'
# /usr/local/lib/ruby/gems/2.2.0/gems/net-sftp-2.1.2/lib/net/sftp/session.rb:182:in `open'
# /usr/local/lib/ruby/gems/2.2.0/gems/net-sftp-2.1.2/lib/net/sftp/session.rb:191:in `open!'
# /usr/local/lib/ruby/gems/2.2.0/gems/net-sftp-2.1.2/lib/net/sftp/operations/file_factory.rb:40:in `open'
# /Users/Ben/remote_filesystem/lib/remote_filesystem/path/sftp.rb:46:in `size'
# ./sftp_spec.rb:72:in `block (3 levels) in <top (required)>'
As far as I can tell from looking at the source code for Net::SFTP::Session, on line 814 of session.rb, channel.send_data is called, but apparently my SFTP Session has a Nil channel for some reason. Can anyone explain how to fix this issue?
If you're caching sftp, the cache might have been invalidated. I came across this exception, because I had tried to call ftp.file.open on an ftp connection that was no longer open.
As mentioned earlier, it means your SFTP session is terminated.
Check TCP logs (wireshark is your friend), the session may be terminated by the peer in the meantime.
A case when such error is happening is if you are doing write(data) operation with data length that exceeds TCP window size on the receiving side. A fix would be to repeat write operations with a buffer, like
io = StringIO.new(data)
sftp_session.file.open(filename, "w") do |file|
while buffer = io.read(BUFFER_SIZE)
file.write(buffer)
end
end

SCP did not finish successfully (1) Error when Trying to Upload from windows to Ubuntu using ruby

My code
IMAGE_DIR = 'D:\File_Server\Nisa_Costcutter\Master Nisa CC Logos'
require 'net/ssh'
require 'net/scp'
def scopy_file(file)
puts "Transferring #{file.path}"
Net::SCP.upload!('192.168.254.5',
'passenger',
file,
'/var/www/pinpointlms.co.uk/shared/logos',
:ssh => {password: '*****'})
end
puts "Starting Upload"
Dir.foreach(IMAGE_DIR) do |name|
if name.length > 4 && name[-4..-1].upcase == '.BMP'
filename=name.strip()
file = File.new(File.join(IMAGE_DIR, filename))
if (Time.now - file.mtime) > 86400
scopy_file(file)
end
end
end
puts "End of Transfer"
I am trying to copy some files from a windows box to an Ubuntu box using Ruby but I get the following output:
Starting Upload
Transferring D:\File_Server\Nisa_Costcutter\Master Nisa CC Logos/Z2579.BMP
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:359:in `block (3 levels) in start_command': SCP did not finish successfully (1)
(Net::SCP::Error) from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:591:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:591:in `do_close'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:586:in `channel_close'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:118:in `close'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:205:in `ensure in start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:205:in `start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:221:in `upload!'
from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:8:in `scopy_file'
from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:24:in`block in <main>'
from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:17:in`foreach'
from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:17:in
`'
I am a ruby beginner so any help you can give me on how to debug this code further will be much appreciated.
Thanks
You probably don't have user access to upload (write) that file in the given directory '/var/www/pinpointlms.co.uk/shared/logos' on your Ubuntu server.
Try to save it without giving it a full path, so it ends up in the user's home directory on the Ubuntu server. If this will work, then your problem is related with the user permission on the server.
In case it's helpful for others, I got the exact same error as this when trying to upload a file to a path that didn't yet exist. scp from shell will allow you to do this, but Net::SCP will fail with this error.
i.e.
scp "my.file" "/foo/bar/"
if /foo exists but /foo/bar/ does not, scp will create /foo/bar and put your file there (assuming permissions allow you to do this).
However - under the same circumstances - this will fail with the error given in the question
scp.upload!(my_file, "/foo/bar/")
The only solution I've found is to first create the path you want locally, and then upload with the :recursive option on, like so:
scp.upload!("bar/", "/foo" :recursive => true)
where ./bar contains my_file.

Resources