jessica
jessica

Reputation: 2610

HDFS + run hdfs commands on linux remote machines

We want to perform the simple command as the following

That use ssh to login to $hadoop_machine machine

And runs hdfs cli as hdfs fsck / , from user hdfs

So we run the following

ssh $hadoop_machine su hdfs -c 'hdfs fsck /' 

but we get

Usage: hdfs [--config confdir] [--loglevel loglevel] COMMAND
       where COMMAND is one of:
  dfs                  run a filesystem command on the file systems supported in Hadoop.
  classpath            prints the classpath
  namenode -format     format the DFS filesystem
  secondarynamenode    run the DFS secondary namenode
  namenode             run the DFS namenode
  journalnode          run the DFS journalnode
  zkfc                 run the ZK Failover Controller daemon
  datanode             run a DFS datanode
  dfsadmin             run a DFS admin client
  envvars              display computed Hadoop environment variables
  haadmin              run a DFS HA admin client
  fsck                 run a DFS filesystem checking utility
  balancer             run a cluster balancing utility
  jmxget               get JMX exported values from NameNode or DataNode.
  mover                run a utility to move block replicas across
                       storage types
  oiv                  apply the offline fsimage viewer to an fsimage
  oiv_legacy           apply the offline fsimage viewer to an legacy fsimage
  oev                  apply the offline edits viewer to an edits file
  fetchdt              fetch a delegation token from the NameNode
  getconf              get config values from configuration
  groups               get the groups which users belong to
  snapshotDiff         diff two snapshots of a directory or diff the
                       current directory contents with a snapshot
  lsSnapshottableDir   list all snapshottable dirs owned by the current user
                                                Use -help to see options
  portmap              run a portmap service
  nfs3                 run an NFS version 3 gateway
  cacheadmin           configure the HDFS cache
  crypto               configure HDFS encryption zones
  storagepolicies      list/get/set block storage policies
  version              print the version

Most commands print help when invoked w/o parameters.

why we cant perform hdfs tasks on remote machine VIA user HDFS?

Upvotes: 0

Views: 825

Answers (1)

Kenster
Kenster

Reputation: 25439

ssh $hadoop_machine su hdfs -c 'hdfs fsck /' 

When you run this, the single quotes are processed by your local shell instance. The command which ssh requests to run on the remote system is:

su hdfs -c hdfs fsck /

su interprets the argument following "-c" as the command to run. The argument is "hdfs", so su invokes hdfs without any arguments.

You need to run ssh in such a way that quotes are passed through to the remote system. This should work:

ssh $hadoop_machine su hdfs -c '"hdfs fsck /"' 
or
ssh $hadoop_machine 'su hdfs -c "hdfs fsck /"'

Either of these should result in ssh requesting to invoke:

su hdfs -c "hdfs fsck /"

Upvotes: 2

Related Questions